第一次使用ListView控件时,我设置了一个将使事件发生的CommandName。
当我单击按钮时应该触发ListView_ItemCommand,但它不是。我点击的时候没什么触发的。
<asp:ListView ID="ListView" runat="server" itemcommand="ListView_onItemCommand"
onitemcommand="ListView_ItemCommand">
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td style="text-align: center">
<asp:Label ID="NameLabel" runat="server" Text='<%# Eval("Name") %>' />
</td>
<td style="text-align: center">
<asp:Label ID="BirthdayLabel" runat="server" Text='<%# Eval("Birthday") %>' />
</td>
<td style="text-align: center">
<asp:Label ID="CourseNameLabel" runat="server"
Text='<%# Eval("CourseName") %>' />
</td>
<td style="text-align: center">
<asp:ImageButton ID="Edit" runat="server" ImageUrl="~/images/edit_icon.png" CommandName="Edit" OnClick="Edit_OnClick" />
</td>
<td style="text-align: center">
<asp:ImageButton ID="Delete" runat="server" ImageUrl="~/images/delete_icon.png" CommandName="Delete" CommandArgument="Delete" />
</td>
</tr>
</ItemTemplate>
protected void ListView_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandArgument.ToString() == "Delete")
{
Label1.Text = "Edit From Button";
}
}发布于 2012-01-16 10:24:12
尝试将命令名更改为
CommandName="Edit"即
CommandName="MyEdit"Command=“编辑”将触发ListView_ItemEditing命令。我认为这将掩盖ItemCommand。但是TBH当我犯了这个错误时,它会因为缺少事件处理程序而使页面崩溃。
所以解释2
另一种解释可能是您正在重新绑定网格。这常常导致事件似乎消失。检查一下你没有这么做
https://stackoverflow.com/questions/8878325
复制相似问题