I have a gridview which show column count 0 when gridview is directly binded to datasource and columns are not defined statically. 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
try this code
foreach (GridViewRow row in yourgridview.Rows)
{
CheckBox myChk = row.FindControl("myControlName") as CheckBox;
if (myChk != null)
{
myChk.Enabled = true;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.