日期:2014-05-18  浏览次数:20469 次

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

------解决方案--------------------
遍历gridview

e.row.cells[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;
..................
}

------解决方案--------------------
this.dataGridView1.Rows[0].toString();
.....
this.dataGridView1.Rows[2]
.....
------解决方案--------------------
发错,应该
this.dataGridView1.Rows[0].Cells[0].toString()
------解决方案--------------------
遍历DataGrid
获取datagrid当前行第一列 第二列 第三列 。。。的值:
MyDataGrid.Rows[i]["第一列"]
MyDataGrid.Rows[i]["第二列"]
MyDataGrid.Rows[i]["第三列"]
------解决方案--------------------
遍历DataGrid 

//取此行第一列的值: 
string str1 = e.Item.Cells[0].Text; 
//取此行第二列的值: 
string str2 = e.Item.Cells[1].Text; 
//取此行第三列的值: 
string str3 = e.Item.Cells[3].Text; 
.................. 
}
------解决方案--------------------
e.Item.Cells[1].Text
------解决方案--------------------
到底是当前行还是第N行