无法在数据列表中触发删除命令
我想触发数据列表控件中的删除命令..但它没有触发..请帮忙..
这是我的代码:
protected void DeleteCommand(object source, DataListCommandEventArgs e)
{
Label2.Text = "hello";
}
这是我的html代码:
<asp:DataList ID="DLImages" runat="server" BorderStyle="None"
DataKeyField="fId" RepeatColumns="4"
RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False"
OnDeleteCommand="DeleteCommand"
onitemdatabound="DLImages_ItemDataBound">
<ItemTemplate>
<asp:ImageButton ID="IBDelete" runat="server" BorderStyle="None" CommandName="Delete" ImageUrl="~/Dashboard/Images/dldelete.png" />
</ItemTemplate>
</asp:DataList>
..
I want to fire the Delete Command in Datalist Control .. but it is not firing .. Help please ..
this is my code :
protected void DeleteCommand(object source, DataListCommandEventArgs e)
{
Label2.Text = "hello";
}
and This is my html code :
<asp:DataList ID="DLImages" runat="server" BorderStyle="None"
DataKeyField="fId" RepeatColumns="4"
RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False"
OnDeleteCommand="DeleteCommand"
onitemdatabound="DLImages_ItemDataBound">
<ItemTemplate>
<asp:ImageButton ID="IBDelete" runat="server" BorderStyle="None" CommandName="Delete" ImageUrl="~/Dashboard/Images/dldelete.png" />
</ItemTemplate>
</asp:DataList>
..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的代码对我来说看起来没问题。它应该触发
DeleteCommand
。但问题是,我确信您在
page_load 事件
中绑定了数据列表,但不是在If(!IsPostBack) 条件下绑定。
当您点击“删除”按钮时会发生什么您的page_load
事件在您的DeleteCommand
之前触发,它会重新绑定DataList
并且您的事件丢失您的 page_load 事件代码应该如下所示...
Your code looks like OK to me. It should fire the
DeleteCommand
.But the problem is that I am sure you are binding the Datalist in your
page_load event
, but not underIf(!IsPostBack) condition.
What happens when you hit Delete button is yourpage_load
event fires before yourDeleteCommand
and it rebinds theDataList
and your event is lostYour page_load event code should look like...