简体   繁体   English

如何使用linkbutton获取在转发器中选择的值?

[英]How to get the value of selected in repeater using linkbutton?

I had a link button in my repeater.. lnkEdit and lnkDelete.. My questions is how I assign the selected value and delete it? 我的转发器中有一个链接按钮.. lnkEdit和lnkDelete ..我的问题是如何分配所选值并删除它?

here's my code: 这是我的代码:

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.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>

Use the commandArgument in you link buttons. 在链接按钮中使用commandArgument。 example: 例:

<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;
        }
}

Is CommandArgument on the button a viable option? 按钮上的CommandArgument是可行的选项吗?

If not, you can try e.Item.DataItem to get a copy back of the data bound item you clicked on and then should be able to read the ID from that? 如果没有,您可以尝试e.Item.DataItem来获取您单击的数据绑定项的副本,然后应该能够从中读取ID吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JavaScript从中继器获取选定标签的值 - How to get value of selected label from repeater using javascript 如何使用pagedatasource突出显示转发器内的linkbutton的所选页面的页码? - How to highlight page number of selected page for a linkbutton inside a repeater using pagedatasource? 如何在中继器中获取RadioButtonlist选定的值? - How to get the RadioButtonlist selected value inside a repeater? 如何在转发器中为LinkBut​​ton的AsyncPostBackTrigger - How to AsyncPostBackTrigger for the LinkButton in the Repeater 如何使用转发器的OnItemCommand触发文本框的事件,而不使用LinkBut​​ton? - How to fire event of textbox with OnItemCommand of a repeater , without using LinkButton? 在转发器控件中获取选定的下拉列表值 - Get selected dropdownlist value inside a repeater control 无法为中继器控件内的LinkBut​​ton设置所选样式 - Cannot set selected style for LinkButton which inside a repeater control 用户单击行时如何获取转发器的项目行ID - How to get items row id of repeater when user clicks rows linkbutton control 如何在使用C#和ASP.NET 4.5的转发器中使用linkbutton - How to use linkbutton in repeater using C# with ASP.NET 4.5 如何使用c#asp.net在LinkBut​​ton的click事件中获取gridview的DataKeyNames值 - How to get DataKeyNames value of gridview inside LinkButton's click event using c# asp.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM