数据列表项目命令事件未触发 [英] Data list Item command event not firing
本文介绍了数据列表项目命令事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家可以帮助我..为什么这个项目命令无法正常工作,当我点击删除按钮?
protected void list_ItemCommand1( object source,DataListCommandEventArgs e)
{
try
{
if (e.CommandName == 删除)
{
HiddenField id1 =(HiddenField)list.Items [e.Item.ItemIndex] .FindControl( HF1\" 跨度>);
if (dbo.deleterecords( image , id =' + id1.Value + ')== true )
{
lbldel.Text = 图片已删除;
}
}
}
catch (例外情况)
{
异常E =前;
}
< asp:DataList < span class =code-attribute> ID = list runat = server RepeatColumns = 5 ShowFooter = true ShowHeader = true 宽度 = 98% OnItemCommand = list_ItemCommand1 >
< ItemTemplate >
< div align = center >
< asp:Image ID = img runat = server BorderColor = white < span class =code-attribute> BorderWidth = 2 高度 = 100
< span class =code-attribute> ImageUrl =' < span class =code-pagedirective><%# 〜/ Image.aspx?id = + Eval( id) %> ' 宽度 = 100px / >
< asp:HiddenField < span class =code-attribute> ID = hf1 runat = server 值 =' <% #Eval( id)%> ' / >
< br / >
< asp:LinkButton ID < span class =code-keyword> = linkremove runat = server CommandName = 删除 文字 = 删除 > < / asp:LinkButton >
< / div > ;
< / ItemTemplate >
< / asp:DataList >
当我点击删除按钮时我无法移除特定图像..
解决方案
您好,
请先在Page_Load事件中调试,然后按F10继续检查是否有任何错误可能是导致问题的原因。
谢谢
Hi can anyone help me.. Why this itemcommand doesn''t works properly, when i click the remove button??
protected void list_ItemCommand1(object source, DataListCommandEventArgs e)
{
try
{
if (e.CommandName == "Remove")
{
HiddenField id1 = (HiddenField)list.Items[e.Item.ItemIndex].FindControl("hf1");
if (dbo.deleterecords("image", "id='" + id1.Value + "'") == true)
{
lbldel.Text = "Image Deleted";
}
}
}
catch (Exception ex)
{
Exception E = ex;
}
<asp:DataList ID="list" runat="server" RepeatColumns="5" ShowFooter="true" ShowHeader="true" Width="98%" OnItemCommand="list_ItemCommand1">
<ItemTemplate>
<div align="center">
<asp:Image ID="img" runat="server" BorderColor="white" BorderWidth="2" Height="100"
ImageUrl='<%# "~/Image.aspx?id="+Eval("id") %>' Width="100px"/>
<asp:HiddenField ID="hf1" runat="server" Value='<%# Eval("id") %>' />
<br />
<asp:LinkButton ID="linkremove" runat="server" CommandName="Remove" Text="Remove"></asp:LinkButton>
</div>
</ItemTemplate>
</asp:DataList>
I cant remove particular image when i click the remove button..
解决方案
Hi,
Please debug first in Page_Load event and by pressing F10 go ahead and check if there is any error which can be the cause of your problem.
Thanks
这篇关于数据列表项目命令事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文