日期:2014-05-17  浏览次数:20395 次

怎样获取GridView的某一列值
我添加了一个GridView控件,列名分别为

id name tel 


每一行后面有一个控件,点击之后想要获取所在的行的id的值,怎么解决?
 

------解决方案--------------------
比如是button
C# code

  protected void Button5_Click(object sender, EventArgs e)
  {
      Button t = (Button)sender;
      GridViewRow drv = (GridViewRow)t.NamingContainer;
      int rowIndex = drv.RowIndex;//得到了行索引,这样既可以通过Rows[].Cells[]访问了
  }

------解决方案--------------------
这个还不简单吗?
 你控件上 绑定 DataKeyNames="PKID"

后台这样获取

PKID = GridView2.DataKeys[GridView2.SelectedIndex].Value.ToString();