如何从DataGridView获取行ID [英] how to Get the Row Id from DataGridView

查看:239
本文介绍了如何从DataGridView获取行ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请有人帮助我,尝试添加到datagridview的链接到另一页时我陷入困境,因为类似的代码正在工作,但我不知道如何获取我单击的行的ID.

Please someone help me, i got stuck when tried to add a link to the datagridview to another page, because the like is working but i dont know how to get the ID of the row i clicked on.

推荐答案

请参见
See here[^]. Maybe one of these solutions can help you.


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        GridViewRow Row = (GridViewRow)((Control)e.CommandSource).NamingContainer;
        int rowID = Convert.ToInt32(GridView1.DataKeys[Row.RowIndex].Value);            }




您应该将primaryKey设置为GridView1.DataKeyNames ..

希望您可以使用它




you should set your primaryKey as GridView1.DataKeyNames..

I hope you can use it


这篇关于如何从DataGridView获取行ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆