我想用asp.net中的gridview控件来删除数据库中的记录,如何实现?
protectedvoidgvShow_RowDeleting(objectsender,GridViewDeleteEventArgse){newEs.BLL.Data...
protected void gvShow_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
new Es.BLL.DataUpdate().deleteVideo("delete from video where vid='" + gvShow.DataKeys[e.RowIndex].Value.ToString() + "'");
gvShow.DataBind();
}
这么写,,一直提示我 索引超出范围,必须为非负值并小于集合大小。 展开
{
new Es.BLL.DataUpdate().deleteVideo("delete from video where vid='" + gvShow.DataKeys[e.RowIndex].Value.ToString() + "'");
gvShow.DataBind();
}
这么写,,一直提示我 索引超出范围,必须为非负值并小于集合大小。 展开
2个回答
展开全部
protected void gdv_Announce_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string keyword = gdv_Announce.DataKeys[e.RowIndex].Value.ToString();
string sql_del = "delete from tsmannouncementmanage where id=" + keyword;
dbCon.deleteData(sql_del);
DataBindTogdv_Announce("order by id desc");
}
datakeynames要设置成id
<asp:GridView ID="gdv_Announce" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" PageSize="5" Style="font-size: 12px" Width="100%" OnRowDataBound="gdv_Announce_RowDataBound"
OnRowDeleting="gdv_Announce_RowDeleting" DataKeyNames="Id" ForeColor="Black"
AllowPaging="True">
<asp:TemplateField HeaderText="删除">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</EditItemTemplate>
<HeaderStyle BackColor="#99CCFF" ForeColor="Black" Wrap="False" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
{
string keyword = gdv_Announce.DataKeys[e.RowIndex].Value.ToString();
string sql_del = "delete from tsmannouncementmanage where id=" + keyword;
dbCon.deleteData(sql_del);
DataBindTogdv_Announce("order by id desc");
}
datakeynames要设置成id
<asp:GridView ID="gdv_Announce" runat="server" AutoGenerateColumns="False" CellPadding="4"
GridLines="None" PageSize="5" Style="font-size: 12px" Width="100%" OnRowDataBound="gdv_Announce_RowDataBound"
OnRowDeleting="gdv_Announce_RowDeleting" DataKeyNames="Id" ForeColor="Black"
AllowPaging="True">
<asp:TemplateField HeaderText="删除">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</EditItemTemplate>
<HeaderStyle BackColor="#99CCFF" ForeColor="Black" Wrap="False" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询