asp.net - FindControl in Gridview is empty with Framework 4.5.2, with Framework 4 is working
问题描述
I add checkboxes
on RowDataBound
in a Gridview
:
for (int i = 1; i < e.Row.Cells.Count; i++)
{
CheckBox cb = new CheckBox();
cb.ID = "Checkbox" + i.ToString();
if (e.Row.Cells[i].Text == "true") cb.Checked = true; else cb.Checked = false;
e.Row.Cells[i].Controls.Add(cb);
}
On Button click I want to read the state of the checkboxes:
foreach (GridViewRow gvr in GV.Rows)
{
for (int i = 1; i < GV.HeaderRow.Cells.Count; i++)
{
CheckBox cb = gvr.FindControl("Checkbox" + i.ToString()) as CheckBox;
if (cb.Checked == true)
{
//To something
}
}
}
This code works with Framework 4 (controls are found) but not with Framework 4.5.2 (controls are empty). How can I fix this? Thanks
解决方案
推荐阅读
- python - pyautogui.moveTo() 有时会失败,我不知道为什么
- selenium - 如何从 GUI 生成 Python Selenium 代码?
- css - 仅使用 css 更改音频属性
- csc - csc -语言版本:?命令产生错误。试图检查编译器的版本
- shopify - Shopify 在 .json 中查找即将推出的商品?
- python - 开发 python 包时使用多处理
- r - 在 R geomorph pacakge 中使用 digit.fixed 函数错放地标的问题
- python - Python中的“&”和“and”有什么区别?
- javascript - TailwindCSS 溢出自动类不适用于 React 列表
- node.js - Passport JS 身份验证问题 - 在 NodeJS 上运行 - 在 Heroku 上出现错误 503 - H13