本文介绍了直放站的ItemCommand没有与火的LinkButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个LinkButton中继器里面,我想,当用户点击LinkButton的删除的项目;在这种情况下,不会触发LinkButton的ItemCommand事件,我的code是如下:
I have a Linkbutton inside a repeater and I want to delete the Item when the user clicks on the Linkbutton; in this case the LinkButton's ItemCommand event is not fired, my code is below:
<asp:Repeater ID="rptSubject" runat="server" OnItemCommand="rptSubject_OnItemCommand">
<ItemTemplate>
<tr>
<td><asp:CheckBox id="chkAll" runat="server"/></td>
<td><%#Eval("SubjectName") %></td>
<td>
<asp:ImageButton ID="imgbtnDelete" ImageUrl="~/assets/images/icons/delete.png" runat="server" CommandName="Delete" CommandArgument='<%#Eval("SubjectID") %>'/>
<asp:LinkButton ID="lnkEditCategory" runat="server" CommandName="EditCategory" CommandArgument='<%#Eval("SubjectID") %>' Text="Edit Category"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
我直放站的ItemCommand事件处理程序是:
my repeater's itemcommand event handler is:
protected void rptSubject_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
// some code
}
if (e.CommandName.Equals("EditCategory"))
{
// some code
}
}
当我点击图像按钮我的命令项事件触发,但是当我点击链接按钮,它没有。
when I click on the image button my item command event fires but when I click on the link button it doesn't.
推荐答案
以下code为我工作:
The following code works for me:
<%@ Page Language="C#" %>
<script type="text/c#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var data = new[]
{
new
{
SubjectID = "1",
SubjectName = "subject name 1"
},
new
{
SubjectID = "2",
SubjectName = "subject name 2"
},
};
rptSubject.DataSource = data;
rptSubject.DataBind();
}
}
protected void RptSubject_OnItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("Delete"))
{
// some code
}
if (e.CommandName.Equals("EditCategory"))
{
// some code
}
}
</script>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<asp:Repeater ID="rptSubject" runat="server" OnItemCommand="RptSubject_OnItemCommand">
<ItemTemplate>
<div>
<asp:CheckBox id="chkAll" runat="server"/>
<%#Eval("SubjectName") %>
<asp:LinkButton ID="imgbtnDelete" runat="server" CommandName="Delete" CommandArgument='<%#Eval("SubjectID") %>' Text="Delete" />
<asp:LinkButton ID="lnkEditCategory" runat="server" CommandName="EditCategory" CommandArgument='<%#Eval("SubjectID") %>' Text="Edit" />
</div>
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>
这篇关于直放站的ItemCommand没有与火的LinkButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!