尝试从网格视图获取数据键值时遇到一些问题。这是代码:
GridView gvForCheckBox = (GridView)e.Item.FindControl("gvProduct") as GridView;
foreach (GridViewRow gr in gvForCheckBox.Rows)
{
//If product name of items in prodList and SPUItemList matches
if (available.Where(x => x.id == gr.Cells[0].Text).Any())
{
//Mark the checkBox checked
CheckBox cb = (CheckBox)gr.Cells[0].FindControl("cbCheckRow");
cb.Checked = true;
//Get the product packaging quantity by productName
string name = gr.Cells[1].Text;
int productQuantity = packBLL.getProductQuantityByName(name);
TextBox tb = (TextBox)gr.Cells[3].FindControl("tbQuantity");
tb.Text = productQuantity.ToString();
}
}
在if (available.Where(x => x.id == gr.Cells[0].Text).Any())
,它应该与第 0 列的值逐行比较,如果 id 匹配,则复选框将被标记。但是,我没有在网格视图中显示 id 列,而是将其设置为 DataKey 值。所以我想知道如何获取网格视图中每一行的数据键。
提前致谢。