在RowDeleting事件中,用下面方式无法取到值: protected void Gvpoint_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
    {   
             //用如下方式,得到的是空值 
      string id = Convert.ToString(Gvpoint.Rows[e.RowIndex].Cells[0].Text);
           //用如下方式可以得到第三列或者其它列的值,但得不到第1列的值(第一列是主键)
        int index = e.RowIndex;
        GridViewRow row = Gvpoint.Rows[index];
        string jobId = Server.HtmlDecode(row.Cells[2].Text);
    
    }
代码如下:
                              ......                <asp:CommandField HeaderText="删除"  ShowDeleteButton="True" >
                    <HeaderStyle HorizontalAlign="Center" />
                </asp:CommandField>
                <asp:CommandField ShowEditButton="True" HeaderText="编辑" />
               </Columns>
                              ......
           

解决方案 »

  1.   

    string id = Gvpoint.Rows[e.RowIndex][0].value.ToString();
      

  2.   

    建议你把ID放DatakeyNames里
    然后用Gvpoin.DataKeys[e.index].value.tostring()就能取到ID值了
    用cells不好保险的
      

  3.   

    string id = Gvpoint.Rows[e.RowIndex].Cells[0].Text.Trim(); 
    一直用這個方法 ,沒出現過什麽問題前臺代碼部分沒看到綁定數據的那幾列,不知道具體情況反正不要寫Visible=false不明白樓主為什麽要用Convert.ToString()
    Text本來就是String類型啊 
    (跟你的問題無關,不用介意)