string ID =MyDataGrid.DataKeys[e.Item.ItemIndex].ToString();  是获取当前行主键列的值。
如何获取datagrid当前行第一列 第二列 第三列 的值?

解决方案 »

  1.   

    private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    //打印出整行的值
    for(int i=0;i<e.Item.Cells.Count;i++)
    {
    Response.Write(e.Item.Cells[i].Text);
    }
    //取此行第一列的值:
    string str1 = e.Item.Cells[0].Text;
    //取此行第二列的值:
    string str2 = e.Item.Cells[1].Text;
    //取此行第三列的值:
    string str3 = e.Item.Cells[3].Text;
    ..................
    }
      

  2.   

    this.dataGridView1.Rows[0].toString();
    .....
    this.dataGridView1.Rows[2]
    .....
      

  3.   

    发错,应该
    this.dataGridView1.Rows[0].Cells[0].toString()
      

  4.   

    遍历DataGrid
    获取datagrid当前行第一列 第二列 第三列 的值:
    MyDataGrid.Rows[i]["第一列"]
    MyDataGrid.Rows[i]["第二列"]
    MyDataGrid.Rows[i]["第三列"]
      

  5.   

    遍历DataGrid //取此行第一列的值: 
    string str1 = e.Item.Cells[0].Text; 
    //取此行第二列的值: 
    string str2 = e.Item.Cells[1].Text; 
    //取此行第三列的值: 
    string str3 = e.Item.Cells[3].Text; 
    .................. 
      

  6.   

    遍历DataGrid //取此行第一列的值: 
    string str1 = e.Item.Cells[0].Text; 
    //取此行第二列的值: 
    string str2 = e.Item.Cells[1].Text; 
    //取此行第三列的值: 
    string str3 = e.Item.Cells[3].Text;