DataGrid 查找控件

发布于 2024-08-13 17:23:47 字数 912 浏览 3 评论 0原文

嗨,

我有一个 DataGrid (是的,如果它是一个 gridview 会更好,但我对此无能为力)

在 itemDataBound 事件中我在每行的第一个单元格中添加一个隐藏字段 我根据某些内容设置其 ID,然后将其 clientID 保存在列表中,以便稍后尝试从中获取值,

但尝试使用 findcontrol 找不到任何内容,

尝试过

这里是 itemdatabound 位

foreach(page in datasource){
HiddenField hidOrder = new HiddenField();
hidOrder.ID = "order_" + page.Id.ToString();
hidOrder.Value = page.Ordering.ToString();
e.Item.Cells[0].Controls.Add(hidOrder);
idList.Add(hidOrder.ClientID);
}

,然后这是一个按钮单击活动..

int numRows = FrontEndDataGrid.Items.Count;
for (int i = 0; i < numRows; i++){
  foreach(string hidID in idList){
    HiddenField hf = FrontEndDataGrid.Items[i].FindControl(hidID) as HiddenField;
    //ssadly this never finds anything
    //have also tried looping around the cells for each 'row' - no luck there either
  }
}

有什么想法吗?

谢谢纳特

HI

I have a DataGrid (yes would be nicer if it was a gridview but nothing i can do about that)

in the itemDataBound event i am adding a hidden field into the first cell of each row
I am setting its ID based on something, and then saving its clientID in a List for later attempts to get the value from it

but try as i might i cant find anything with findcontrol

have tried

here is the itemdatabound bit

foreach(page in datasource){
HiddenField hidOrder = new HiddenField();
hidOrder.ID = "order_" + page.Id.ToString();
hidOrder.Value = page.Ordering.ToString();
e.Item.Cells[0].Controls.Add(hidOrder);
idList.Add(hidOrder.ClientID);
}

then this is a button click event..

int numRows = FrontEndDataGrid.Items.Count;
for (int i = 0; i < numRows; i++){
  foreach(string hidID in idList){
    HiddenField hf = FrontEndDataGrid.Items[i].FindControl(hidID) as HiddenField;
    //ssadly this never finds anything
    //have also tried looping around the cells for each 'row' - no luck there either
  }
}

any ideas?

thanks

nat

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋叶绚丽 2024-08-20 17:23:47

好吧,看来我有 clientID ,并且我需要普通 id

所以更改了 idList.Add(hidOrder.ID);
一切都很好

ok it seems i had the clientID , and i need the the plain id

so changed the idList.Add(hidOrder.ID);
and all is well

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文