[英]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> <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>
<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.