I need to figure out how to bind a CheckBox value in a GridView, I have written CheckBox.Checked= DataBinder.Eval(Container.DataItem, "IsSubscribed") in GridView, but the CheckBox is always checked, even when IsSubscribed
is false.
I have bound the grid in Page_Load
, before the page has posted back. Here is my code:
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox
ID="chkIsSubscribed" runat="server" HeaderText="IsSubscribed"
Checked='<%# DataBinder.Eval(Container.DataItem, "IsSubscribed") %>'/>
</ItemTemplate>
</asp:TemplateField>
Thanks.
Put this code as your Item Template element:
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkIsSubscribed" runat="server" HeaderText="IsSubscribed"
Checked='<%#bool.Parse(Eval("IsSubscribed").ToString())%>' />
</ItemTemplate>
</asp:TemplateField>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With