gridview如何获取行ID

后台代码protectedvoidGridView1_RowDeleting(objectsender,GridViewDeleteEventArgse){strings... 后台 代码

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

string strsql2 = "delete from [User] where User_ID="
SqlConnection sqlconn = new SqlConnection(strcon);
sqlconn.Open();
SqlCommand sqlcmd2 = new SqlCommand(strsql2, sqlconn);
sqlcmd2.ExecuteNonQuery();

}
}
前台代码 <form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="User_ID" DataSourceID="User" RowHeaderColumn="User_ID"
PageSize="5" AllowPaging="True" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" AutoGenerateSelectButton="True"
BackColor="#FF6600" BorderColor="#66FF99" BorderWidth="2px"
EmptyDataText="没有数据" ForeColor="#FFFF66"
onrowdeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="User_ID" HeaderText="User_ID" InsertVisible="False"
ReadOnly="True" SortExpression="User_ID" />
<asp:BoundField DataField="UserName" HeaderText="UserName"
SortExpression="UserName" />

<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Address" HeaderText="Address"
SortExpression="Address" />
<asp:BoundField DataField="Birthday" HeaderText="Birthday"
SortExpression="Birthday" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="User" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"
SelectCommand="SELECT * FROM [User]"></asp:SqlDataSource>
</div>
</form>

怎么获取ID的值
展开
 我来答
桖听sJ
2010-07-28 · TA获得超过451个赞
知道答主
回答量:618
采纳率:100%
帮助的人:183万
展开全部
Container.ItemIndex +1,第一行就是1,第二行就是2,类推....
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式