我有一个 DataGrid,其中数据源与 SqlDataReader 对象绑定(bind):
SqlDataReader areader = runner.Reader;
dgSearchResults.DataSource = areader;
dgSearchResults.DataBind();
我已经为我的网格创建了一个 ItemDataBound 事件,我想检查每个项目绑定(bind)时特定列/单元格的值,以便我可以启用/禁用一些标志。
如何获取 ItemDataBound 上特定单元格“SvcID”的值?
这是我的代码:
public void dgSearchResults_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (ViewState["SvcIDs"] != null)
{
if (e.Item != null)
{
var svcIds = (List<int>) ViewState["SvcIDs"];
if (svcIds.Contains(Convert.ToInt32(**DataGrid SvcID Goes Here**))
{
//TODO: enable/disable some icons
}
}
}
}
我以前使用过 RowDataBound 事件,但没有用于 DataGrid 控件,并且所需的步骤似乎有点不同。
根据我的 SvcIds(使用索引)列表检查 DataGrid 中“SvcID”列的值的代码是什么?
谢谢
最佳答案
您可以使用以下命令访问单元格:
e.Item.Cells[index].Text;
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagriditemeventargs.item.aspx
关于c# - 使用 DataGrid ItemDataBound 事件检查值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18258333/