title: Checkbox refused to bind data
body: <p>When the data is loaded into the gridview, the boolean values should show in the checkboxes. Checkbox should be in editable format. </p>
  
  <p>I am getting number of errors: Invalid cast, String is not in valid format etc.</p>
  
  <p>I searched in Google and here as well. There are number of devs who faced same or similar issues and have managed to get it solved. </p>
  
  <p><code>Mon_S1</code> is a boolean (true, false). Changed to string to test out following code snippets. </p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/18482132">1 : changed the values in db to be string and gives : System.FormatException: String was not recognized as a valid Boolean.</a> and - <a href="https://stackoverflow.com/q/7411058/2061309">3 : same issue</a></li>
  </ul>
  
  <p><code>checked='&lt;%# bool.Parse(Eval("Mon_S1").ToString()) %&gt;'</code></p>
  
  <ul>
  <li><a href="http://www.codeproject.com/Questions/361831/System-InvalidCastException-Specified-cast-is-not" rel="nofollow noreferrer">2 : with bool values : System.InvalidCastException: Specified cast is not valid.</a></li>
  </ul>
  
  <p><code>checked='&lt;%# Eval("Mon_S1") %&gt;'</code></p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/8799986/2061309">4 : this shows an empty editable checkbox</a></li>
  </ul>
  
  <p><code>checked='&lt;%# Eval("Mon_S1").ToString().Equals("1") %&gt;'</code>
  <code>checked='&lt;%# Bind("Mon_S1").ToString().Equals("1") %&gt;'</code></p>
  
  <p>But no matter what combination of the answers I tried, it's not displaying the data as per the db which infact has boolean values. </p>
  
  <p>Stacktrace for the following cast error:</p>
  
  <pre><code>Line 143:        &lt;asp:TemplateField HeaderText="MS1"&gt;
  Line 144:            &lt;ItemTemplate&gt;
  Line 145:                &lt;asp:CheckBox ID="cbMS1" runat="server" checked='&lt;%# Eval("Mon_S1") %&gt;'/&gt;
  Line 146:            &lt;/ItemTemplate&gt;
  Line 147:        &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <hr>
  
  <p><strong>Stack Trace:</strong></p>
  
  <pre><code>[InvalidCastException: Specified cast is not valid.]
     ASP.testschedule_aspx.__DataBinding__control38(Object sender, EventArgs e) in C:\Test - 0509 working\TestSchedule.aspx:145
     System.Web.UI.Control.OnDataBinding(EventArgs e) +92
     System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +85
     System.Web.UI.Control.DataBind() +15
     System.Web.UI.Control.DataBindChildren() +187
     System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +94
     System.Web.UI.Control.DataBind() +15
     System.Web.UI.Control.DataBindChildren() +187
     System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +94
     System.Web.UI.Control.DataBind() +15
     System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +167
     System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3724
     System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67
     System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14
     System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123
     System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33
     System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
     System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
     System.Web.UI.WebControls.GridView.DataBind() +4
     TestSchedule.TestSchedule.BindGridViewDataSchedule() in C:\Test - 0509 working\TestSchedule.aspx:39
     TestSchedule.TestSchedule.Page_Load(Object sender, EventArgs e) in C:\Test - 0509 working\TestSchedule.aspx.cs:22
     System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
     System.Web.UI.Control.OnLoad(EventArgs e) +92
     System.Web.UI.Control.LoadRecursive() +54
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/L8VoT.png" alt="enter image description here"></p>