gpt4 book ai didi

c# - 如何获取 GridView 中特定单元格内的所有控件

转载 作者:太空宇宙 更新时间:2023-11-03 15:02:35 25 4
gpt4 key购买 nike

我在 GridView 中动态生成 CheckBox 控件。现在我需要验证是否至少选择了一个 CheckBox,并且在保存数据时我需要遍历单元格内的所有控件。

现在的问题是我无法执行 grdApproverDetails.Rows[i].FindControl('controlID'),因为 ID 是根据控件计数动态生成的。如图this线程。

这是 GridView 的外观,Approver Name 是我需要在其中查找控件(如果是 CheckBox)的列。 enter image description here

如何获取 GridView 单元格内的所有控件并进行迭代?

最佳答案

您可以使用(手写代码)获取复选框:

foreach (GridViewRow row in grdApproverDetails.Rows)
{
for (int k = 0; k < row.Cells.Count; k++)
{
for (int i = 0; i < row.Cells[k].Controls.Count; i++)
{
Control control = row.Cells[k].Controls[i];
if(control is CheckBox)
{
CheckBox chk = control as CheckBox;
if(chk != null && chk.Checked)
//...
}
}
}
}

关于c# - 如何获取 GridView 中特定单元格内的所有控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45409764/

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