gpt4 book ai didi

c# - 使用 DataGrid ItemDataBound 事件检查值

转载 作者:行者123 更新时间:2023-11-30 20:55:30 24 4
gpt4 key购买 nike

我有一个 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 控件,所需的步骤看起来有点不同。

根据我的 SvcId(使用索引)列表检查我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com