3

我无法将选定的 gridview 行的列数据显示到文本框中。我的网格视图中有一个选择列。要显示的选定行已声明为字符串。

代码 :

tbpolicereport.Text = GVStatusReportPolice.SelectedRow.Cells[2].Text;

更新 :

上面的代码是正确的。当您通过 sqldatasource 将 gridview 与 sql server 绑定时,将使用此代码。单元格编号只是您要显示的列号。

调试后,我意识到该值确实通过了,但是它无法在我的文本字段上显示出来。重新创建整个表单后,值神奇地出现。

4

2 回答 2

1

您需要指定行和列索引。
值可以这样取:

int rowindex = GVStatusReportPolice.CurrentCell.RowIndex;
int columnindex= = GVStatusReportPolice.CurrentCell.ColumnIndex; 

lblCID.Text = GVStatusReportPolice.Rows[rowindex].Cells[columnindex].Value.ToString();
于 2013-05-17T07:50:09.333 回答
1

尝试这个 ..

tbpolicereport.Text = GVStatusReportPolice.Currentcell.Value;
于 2013-05-17T07:56:05.197 回答