想获取指定Cell值  代码如下,但内容总为空,  cells 0,1,2...都是空  ,不知道为什么,, 还有其他方式获取伐, 如设置 datakey 
        protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int index = Convert.ToInt32(e.CommandArgument);
            this.GridView2.Rows[index].Cells[0].Text 内容总是为空
        }

解决方案 »

  1.   

    呵呵 你要调试下,然后会发现这个this.GridView2.Rows[index].Cells[0]其实是一个控件.
    Lable lab = this.GridView2.Rows[index].Cells[0] as Lable;
    lab.Text应该就是你要的值
      

  2.   

    RowCommand事件发生时候,gridview已经填充好变成一个table展现到页面上了,这样Rows[]Cell[]取不到数据
    给楼主提供一个方法,可以把绑定到gridview的数据变成dataview或者dataTable放在session中,
    通过 int index = Convert.ToInt32(e.CommandArgument)
    找到选择的那一行,然后从dataview或者dataTable取相应的值
      

  3.   

    不是的1. 首先你要确定你的cell是不是用了模板列,也就是这个cell里面是不是有控件,如果有控件
    那么就要获取控件里面的值,而不是cell里面的值。比如cell里面是一个linkbutton
     则: LinkButton linkButton=(LinkButton)this.GridView2.Rows[index].Cells[0].FindControl("linkButtonID");string value=linkButton.Text;2. 其次检查你的e.CommandArgument,是否和行数相符。