C# ASP.NET怎么根据GridView某一列的值,来删除某一行?
比如以下这个:IDLET1A2B3C1根据ID的列找到某个值2删除ID为某个值的那一行请问该怎么做?代码怎么写?...
比如以下这个:
ID LET
1 A
2 B
3 C
1根据ID的列找到某个值
2删除ID为某个值的那一行
请问该怎么做?
代码怎么写? 展开
ID LET
1 A
2 B
3 C
1根据ID的列找到某个值
2删除ID为某个值的那一行
请问该怎么做?
代码怎么写? 展开
1个回答
展开全部
我直接给你粘我的代码,你有不明白的私信我.
前台:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="tab" Width="700px" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="DepartmentName" HeaderText="部门名称" ItemStyle-Width="100px" />
<asp:BoundField DataField="DepartmentDes" HeaderText="部门简介" />
<asp:CommandField ShowEditButton="True">
<ItemStyle Width="100px" />
</asp:CommandField>
<asp:CommandField DeleteText="<span onclick="return confirm('确认删除吗?');">删除</span>" ShowDeleteButton="True">
<ItemStyle Width="100px" />
</asp:CommandField>
</Columns>
</asp:GridView>
后台:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//if (!AdminLib.CheckPowers(UserInfo, 89))
// Response.Redirect("/HHC/error.aspx?m=您没有删除管理员的权限,请联系管理员!");
int id = Utils.StrToInt(GridView1.DataKeys[e.RowIndex].Value, -1);
if (AdminLib.DelDepartment(id))
BindData();
}
前台:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="tab" Width="700px" OnRowEditing="GridView1_RowEditing" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" OnRowUpdating="GridView1_RowUpdating" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="DepartmentName" HeaderText="部门名称" ItemStyle-Width="100px" />
<asp:BoundField DataField="DepartmentDes" HeaderText="部门简介" />
<asp:CommandField ShowEditButton="True">
<ItemStyle Width="100px" />
</asp:CommandField>
<asp:CommandField DeleteText="<span onclick="return confirm('确认删除吗?');">删除</span>" ShowDeleteButton="True">
<ItemStyle Width="100px" />
</asp:CommandField>
</Columns>
</asp:GridView>
后台:
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//if (!AdminLib.CheckPowers(UserInfo, 89))
// Response.Redirect("/HHC/error.aspx?m=您没有删除管理员的权限,请联系管理员!");
int id = Utils.StrToInt(GridView1.DataKeys[e.RowIndex].Value, -1);
if (AdminLib.DelDepartment(id))
BindData();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询