English 中文(简体)
如何利用联系网获得在重复体中选定的数值?
原标题:How to get the value of selected in repeater using linkbutton?

我的复读中有一个连接塔顿。 Edit and lnkDelete. 我的问题是,我如何分配选定的价值并删除它?

我的守则如下:

protected void rptrInsurance_ItemCommand(object source, RepeaterCommandEventArgs e)
{

    try
    {

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            switch (e.CommandName)
            {
                case "Delete":
                    {
                        HCSInsurance oInsuranceDelete = new HCSInsurance();
                        Insurance oInsurance = new Insurance();
                       // oInsurance.InsuranceCode.ID = "2";
                        oInsuranceDelete.DeleteInsurance(oInsurance);
                    }
                    break;
                case "Edit":
                    {

                    }
                    break;
                default:
                    {

                    }
                    break;
            }
        }

    }

    catch (Exception ex)
    {

    }

}

asp.net

<asp:LinkButton ID="lnkEdit" runat="server" onclick="lnkEdit_Click" CommandName="Edit">Edit</asp:LinkButton>&nbsp;<asp:LinkButton 
ID="lnkDelete" runat="server" onclick="lnkDelete_Click" CommandName="Delete" OnClientClick="if (!confirm( Are you sure do you want to delelte it? )) return false;">Delete</asp:LinkButton>
            </td>
最佳回答

利用你在座的指挥区。 例如:

<asp:Repeater ID="rptrInsurance" runat="server" 
    OnItemCommand="rptrInsurance_ItemCommand">
    <ItemTemplate>
<asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit" CommandArgument= <%# Eval("ID") %> >Edit</asp:LinkButton>&nbsp;
<asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" CommandArgument= <%# Eval("ID") %>  OnClientClick="if (!confirm( Are you sure do you want to delelte it? )) return false;">Delete</asp:LinkButton>
    </ItemTemplate>
</asp:Repeater>  


protected void rptrInsurance_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    switch (e.CommandName)
        {
            case "Delete":
                {
                    HCSInsurance oInsuranceDelete = new HCSInsurance();
                    Insurance oInsurance = new Insurance();
                    oInsurance.InsuranceCode.ID = e.CommandArgument;
                    oInsuranceDelete.DeleteInsurance(oInsurance);
                }
                break;
            case "Edit":
                {

                }
                break;
            default:
                {

                }
                break;
        }
}
问题回答

纽伦堡的“商法”是可行的选择吗?

如果没有,你可以尝试<代码>。 项目.DataItem,以获得您点击的受数据约束项目的复印件,然后从中读到该笔数据?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签