title: Asp.net Gridview Rowdata is coming empty and Unchecked
body: <p>I have a requirement where i need to add column names and rowdatabound values dynamically .I has managed to get Column names dynamically .According to my need i want values to be displayed in the form of checkboxes in the rows of the grid either in checked form or unchecked based on condition but here every thing is coming in unchecked formate ..</p>
  
  <p>I am using .net membership  Role table...</p>
  
  <p>Here is my code for gridview Dynamic column allocation..</p>
  
  <pre><code>protected void BindGridviewData()
  {
  
      var role = from MembershipUser u in Membership.GetAllUsers()
                 select new
                 {
                     User = u.UserName,
                     Role = string.Join(",", Roles.GetRolesForUser(u.UserName))
                 };
  
  
      DataTable dTable = new DataTable();
      string[] rolesarr = Roles.GetAllRoles();
      // add column for user name 
      dTable.Columns.Add("Username", typeof(string));
      // then add all the roles as columns 
      Array.ForEach(rolesarr, r =&gt; dTable.Columns.Add(r));
  
      List&lt;string&gt; tempfield = new List&lt;string&gt;();
  
      foreach (DataColumn column in dTable.Columns)
      {
         string ColName = column.ColumnName;
         tempfield.Add(ColName);
      }
  
      for (int i = 0; i &lt; tempfield.Count; i++)
      {
  
      string tempfieldname = tempfield[i];
      TemplateField temp = new TemplateField();
      if (i == 0)
      {
          temp.HeaderText = tempfieldname;
  
          tempfieldname = string.Empty;
      }
      else {
  
          temp.ItemTemplate = new MyTemplate();
          temp.HeaderText = tempfieldname;
          tempfieldname = string.Empty;
      }
      GridView1.Columns.Add(temp);
      }
  </code></pre>
  
  <p>Now Here i am checking values to be checked or uncked..</p>
  
  <pre><code>foreach (MembershipUser u in Membership.GetAllUsers())
      {
          DataRow dRow = dTable.NewRow();
          dRow[0] = u.UserName;
  
          string[] roles = Roles.GetRolesForUser(u.UserName);
  
          dRow[1] = roles.Contains("Admin") ? true : false;
          dRow[2] = roles.Contains("DPAO User") ? true : false;
          dRow[3] = roles.Contains("GeneralUser") ? true : false;
          dTable.Rows.Add(dRow);
      }
      GridView1.DataSource = dTable;
      GridView1.DataBind();
  }
  </code></pre>
  
  <p>Upto here values are coming fine in <strong>dTable</strong> but once flow goes to rowdatabound event </p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  
  }
  </code></pre>
  
  <p>On rowdatabound event flow automatically moves to <strong>custom control</strong> class which is ...</p>
  
  <pre><code>public class MyTemplate : ITemplate
    {
  public void InstantiateIn(Control container)
  {
      CheckBox chk = new CheckBox();
      chk.ID = "chk";
      container.Controls.Add(chk);
  }
  
  }
  </code></pre>
  
  <p>And from here all checkboxes are displaying as unchecked ...</p>
  
  <p>Please guys help me ..
  Thanks in advance...</p>