该字段用的是模板,希望在点击该行编辑时,得到该行这个字段的值,
   我用了
    string weight = GridView1.Rows[e.RowIndex].FindControl("weight").ToString();
   这个语句,但是并没有取出该字段。请问有什么好办法。

解决方案 »

  1.   


    string weight = GridView1.Rows[e.RowIndex].FindControl("weight").ToString();
    改成:
    string weight = GridView1.Rows[e.RowIndex].FindControl("weight").Text;

    string weight = GridView1.Rows[e.RowIndex].FindControl("weight").InnerText;
    你的是什么控件..
      

  2.   

    string weight = this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString(); 
      

  3.   

    string weight = this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString(); 
      

  4.   

    string weight = this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString();
    // 你这个字段weight在GridView里的第几列。
    // 一楼的方法很好~
    // 话说3楼很好很强大~
      

  5.   

    string weight = GridView1.Rows[e.RowIndex].FindControl("weight").Text;
    像一楼这样,你用的是什么控件
      

  6.   

    我依然觉得有点不对劲,应该按照是这样吧        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                string weight= dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
            }楼上面写的rows[].cells[].text这个text属性,我没有找到,我觉得应该是Value
      

  7.   

    string weight= GridView1.Rows[e.RowIndex].FindControl("weight").Text;
    用这个会显示
    “System Web.UI.Control"不包含“Text”的定义,并且找不到可接受类型为“System Web.UI.Control"的第一个参数的扩展方法“Text”(是否缺少using指令或程序集引用)
    请问是个什么问题?
      

  8.   

    这里的weight是模板里面EditItemTemplate是一个textbox
      

  9.   


    //主要是看你那个CELL中放的是什么控件
    如果是TextBox
    string strValue= ((TextBox)GridView1.Rows[e.RowIndex].FindControl("weight")).Text.Trim();