index.aspx
------------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnItemCommand="DataList1_ItemCommand">
<asp:ImageButton ID="del" runat="server" ImageUrl="~/images/icon/icon_delete_reply.gif" commandname = "DRdel" />
</DataList>
index.aspx.cs
------------------------------------------------------------------------------------
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemIndex != -1 && e.CommandName == "DRdel")//判断索引和CommandName
{
int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//获取激发事件时的行的主键ID
SqlConnection one = conn.sqlconn();
one.Open();
String Sql = "delete from book where id=" + id;
SqlCommand cmd = new SqlCommand(Sql, one);
cmd.ExecuteNonQuery();
fanye(); }
} 我把linkbotton改成image图片按钮空间就不能删除,为什么?
本来index.aspx 的删除是: <asp:LinkButton ID="LinkButton1" runat="server" CommandName="DRdel">删除 </asp:LinkButton>
------------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnItemCommand="DataList1_ItemCommand">
<asp:ImageButton ID="del" runat="server" ImageUrl="~/images/icon/icon_delete_reply.gif" commandname = "DRdel" />
</DataList>
index.aspx.cs
------------------------------------------------------------------------------------
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemIndex != -1 && e.CommandName == "DRdel")//判断索引和CommandName
{
int id = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex].ToString());//获取激发事件时的行的主键ID
SqlConnection one = conn.sqlconn();
one.Open();
String Sql = "delete from book where id=" + id;
SqlCommand cmd = new SqlCommand(Sql, one);
cmd.ExecuteNonQuery();
fanye(); }
} 我把linkbotton改成image图片按钮空间就不能删除,为什么?
本来index.aspx 的删除是: <asp:LinkButton ID="LinkButton1" runat="server" CommandName="DRdel">删除 </asp:LinkButton>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货