当前位置: 代码迷 >> ASP.NET >> GridView1_RowDataBound事件中怎么获得gridview当前行的ID
  详细解决方案

GridView1_RowDataBound事件中怎么获得gridview当前行的ID

热度:7908   发布时间:2013-02-25 00:00:00.0
GridView1_RowDataBound事件中如何获得gridview当前行的ID
protected   void   GridView1_RowDataBound(object   sender,   GridViewRowEventArgs   e){
                        if   (e.Row.RowIndex   >   -1){
                                e.Row.Cells[1].Attributes.Add( "ondblclick ",   "window.open( 'editWare.aspx?id= "   +   这该怎么写+ " ',null, 'width=400,height=148,left=300,top=200 '); ");
                        }
                }

------解决方案--------------------------------------------------------
你这个ID是数据库中的主键,还是gridview中的第几行。
------解决方案--------------------------------------------------------
问题是你 ID 列你帮定上来没有

如果邦定上来了 就好写了

e.Row[ "ID列的名字 "].Text.ToString(); (文本列的话)

要是其他类型的列,你在找控件取值就可以了
------解决方案--------------------------------------------------------
首先:你要设置Gridview的属性DataKeys,设为你的ID字段.

其次:在代码里通过GridView1.DataKeys[row.RowIndex].Value取得当前行的ID.
------解决方案--------------------------------------------------------
e.Row.Cells[ 你主键的列索引]
  相关解决方案