读书人

怎么获取datagrid当前行第一列 第二列

发布时间: 2012-01-11 22:28:46 作者: rapoo

如何获取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行

读书人网 >asp.net

热点推荐