[英]Why column count in gridview is 0 when columns are binded dynamically from datatable
I have a gridview which show column count 0 when gridview is directly binded to datasource and columns are not defined statically. 我有一个gridview,当gridview直接绑定到数据源并且列不是静态定义时,它显示列数为0。 I am unable to come up with this problem. 我无法提出这个问题。
I tried this below code: 我尝试下面的代码:
foreach (GridViewRow row in gv_services.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < gv_services.Columns.Count; i++)
{
if (row.Cells[i].Controls[0].GetType() == typeof(CheckBox))
{
CheckBox checkBox = row.Cells[i].Controls[0] as CheckBox;
checkBox.Enabled = true;
// checkBox.CheckedChanged += new EventHandler(chck_CheckedChanged);
}
}
}
}
If i understood correctly you are trying to loop through gridview rows and enable checkbox based on your conditions 如果我正确理解,您正在尝试遍历gridview行并根据您的条件启用复选框
try this code 试试这个代码
foreach (GridViewRow row in yourgridview.Rows)
{
CheckBox myChk = row.FindControl("myControlName") as CheckBox;
if (myChk != null)
{
myChk.Enabled = true;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.