Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic CheckBoxes in GridView Rows are not showing properly in ASP.NET
    text
    copied!<p>I have a gridview in which i am showing values to be checked or unchecked in gridview rows checkboxes..Now i want to these values dynamically in gridview rows but its not going to happen ..All of the checkboxes are coming checked whereas result should be different .. </p> <p>here is my hardcoded code condition to show the result which is coming fine...</p> <pre><code>string[] rolesarr = Roles.GetAllRoles(); DataTable dTable = new DataTable(); dTable.Columns.Add("Select", typeof(bool)); dTable.Columns.Add("Username", typeof(string)); Array.ForEach(rolesarr, r =&gt; dTable.Columns.Add(r, typeof(bool))); foreach (MembershipUser u in Membership.GetAllUsers()) { DataRow dRow = dTable.NewRow(); dRow[0] = false; dRow[1] = u.UserName; string[] roles = Roles.GetRolesForUser(u.UserName); dRow[2] = roles.Contains("Admin") ? true : false; dRow[3] = roles.Contains("DPAO User") ? true : false; dRow[4] = roles.Contains("GeneralUser") ? true : false; dTable.Rows.Add(dRow); } GridView1.DataSource = dTable; GridView1.DataBind(); </code></pre> <p>Now i want to make this condition dynamic for which i have written code..</p> <pre><code>string[] rolesarr = Roles.GetAllRoles(); DataTable dTable = new DataTable(); dTable.Columns.Add("Select", typeof(bool)); dTable.Columns.Add("Username", typeof(string)); Array.ForEach(rolesarr, r =&gt; dTable.Columns.Add(r, typeof(bool))); foreach (MembershipUser u in Membership.GetAllUsers()) { DataRow dRow = dTable.NewRow(); dRow[0] = false; dRow[1] = u.UserName; string[] roles = Roles.GetRolesForUser(u.UserName); for (int i = 0; i &lt; roles.Length; i++) { string rol = roles[i]; for (int j = 2; j &lt; dTable.Columns.Count; j++) { dRow[j] = roles.Contains(rol) ? true : false; } } dTable.Rows.Add(dRow); } GridView1.DataSource = dTable; GridView1.DataBind(); </code></pre> <p>And Here is my RowDatabound event for checkboxes ..</p> <pre><code>protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox c0 = (CheckBox)e.Row.Cells[0].Controls[0]; CheckBox c2 = (CheckBox)e.Row.Cells[2].Controls[0]; CheckBox c3 = (CheckBox)e.Row.Cells[3].Controls[0]; CheckBox c4 = (CheckBox)e.Row.Cells[4].Controls[0]; c0.Enabled = c2.Enabled = c3.Enabled = c4.Enabled = true; } } </code></pre> <p>Please guys help me ..Thanks in advance...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload