gridview 怎样删除一行
我绑定的数据源是数据库,在GRIDVIEW中显示两个字段(studentNO,studentName),我在网上看了上,要获取主键值,高手给写一个细点的protected...
我绑定的数据源是数据库,在GRIDVIEW中显示两个字段(studentNO,studentName),我在网上看了上,要获取主键值,高手给写一个细点的protected void D1_SelectedIndexChanged(object sender, EventArgs e)化码,我就五分了,
展开
3个回答
展开全部
源代码
<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="typeid"
AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" AutoGenerateEditButton="True"
Width="483px" OnRowUpdating="GridView2_RowUpdating" OnRowDataBound="GridView2_RowDataBound"
OnRowDeleting="GridView2_RowDeleting" OnRowCommand="GridView2_RowCommand">
DataKeyNames是你的主键
后台代码
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
co = new common(); //数据库链接类
string sql = "Delete from [dbo].[T-InvestItem] where id='" + GridView1.DataKeys[e.RowIndex].Value + "'";
co.Sql_ExecuteSql(sql);
}
<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="typeid"
AutoGenerateColumns="False" AllowSorting="True" AllowPaging="True" AutoGenerateEditButton="True"
Width="483px" OnRowUpdating="GridView2_RowUpdating" OnRowDataBound="GridView2_RowDataBound"
OnRowDeleting="GridView2_RowDeleting" OnRowCommand="GridView2_RowCommand">
DataKeyNames是你的主键
后台代码
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
co = new common(); //数据库链接类
string sql = "Delete from [dbo].[T-InvestItem] where id='" + GridView1.DataKeys[e.RowIndex].Value + "'";
co.Sql_ExecuteSql(sql);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询