Reputation: 11393
I try to Bind Checkbox Checked property in side ListView
Like this :
<asp:CheckBox ID="chk_holi_sal" runat="server" Class="chk_holi_sal" Checked="<%#:Item.HasSal%>" />
public bool HasSal
{
get { return SALARY_CALC == 1; }
}
But I get the following compiler error :
Compiler Error Message: CS0030: Cannot convert type 'string' to 'bool'
I check the values of <%#:Item.HasSal%>
and find it 's equal True
OR False
Why do I get this error all the time ?
According to the Answers to use Eval
instead of take advantage of the strongly type
value for the ListView
Control ,I face new exception :
Upvotes: 1
Views: 1411
Reputation: 11393
The Following line worked with me :
<input id="chk_holi_sal" class="chk_holi_sal" type="checkbox" checked=' <%# Eval("HasSal") %>' disabled="disabled" runat="server" value="<%#:Item.HasSal%>" />
I try to use the strongly-Typed
feature but it fails,I have to use Eval
.
Upvotes: 1
Reputation: 616
try with this code
<asp:CheckBox ID="chk_holi_sal" runat="server" Checked="<%# Convert.ToBoolean(Eval("Item.HasSal")) %>" />
or with ternary operator
<asp:CheckBox ID="chk_holi_sal" runat="server" Checked=
<%# Convert.ToBoolean(Eval("Item.HasSal")) ? true : false %> />
Upvotes: 2