0

我的 gridview 填充了这样的文章对象

var sel = (Article)cmbArticleList.SelectedItem;

 DataRow newRow = articlesTable.NewRow();
 newRow["CODE"] = sel.Code;
 newRow["NAME"] = sel.Name;
 newRow["PRICE"] = sel.Price;

 articlesTable.Rows.Add(newRow);
 articlesGridView.DataSource = articlesTable;

我想知道如何识别该网格的选定行,例如 onLabelSelectedRow.Text应该填充选定的行代码文本。

4

1 回答 1

1

首先,您可以像这样获得您选择的行;

//For multiple row selection.
IList rows = dg.SelectedItems;

//For single row selection;
DataRowView row = (DataRowView)dg.SelectedItems[0];

//You can then access them via their column name;
row["yourColumnName"];

//So to assign to say your label..
LabelSelectedRow.Text = row["CODE"] + " " + " row[NAME] + " " + row[PRICE];

编辑:您可以将此代码放在数据网格单击事件之一中,也许是 RowSelected。

于 2013-07-02T08:26:37.793 回答