P
Paul
I am trying to display the contents of a numeric database column whose
values are restricted to 0 or 1 as a checked or unchecked checkbox in my
datagrid. I can display the database column's contents using an ordinary
bound column so I know that I am successfully retrieving the data. The
snippet from my aspx file where I try to display via a checkbox is:
<asp:BoundColumn DataField="Location" HeaderText="Location">
<HeaderStyle Width="100px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Enabled">
<HeaderStyle Width="25px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox runat="server" Checked='<%#
DataBinder.Eval(Container, "DataItem.Enabled") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
When the page is being generated, the first row of the grid shows the proper
data in the "Location" bound column but an exception is thrown with the
message:
"Specified cast is invalid."
when the "Enabled" column in the first row is being processed. I have tried
things such as:
<asp:CheckBox runat="server" Checked='<%# ((int)DataBinder.Eval(Container,
"DataItem.Enabled"))==1 %>'>
and
<asp:CheckBox runat="server" Checked='<%# (((int)DataBinder.Eval(Container,
"DataItem.Enabled"))==1)? true : false %>'>
without any success.
Any suggestions would be appreciated.
values are restricted to 0 or 1 as a checked or unchecked checkbox in my
datagrid. I can display the database column's contents using an ordinary
bound column so I know that I am successfully retrieving the data. The
snippet from my aspx file where I try to display via a checkbox is:
<asp:BoundColumn DataField="Location" HeaderText="Location">
<HeaderStyle Width="100px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Enabled">
<HeaderStyle Width="25px"></HeaderStyle>
<ItemTemplate>
<asp:CheckBox runat="server" Checked='<%#
DataBinder.Eval(Container, "DataItem.Enabled") %>'>
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
When the page is being generated, the first row of the grid shows the proper
data in the "Location" bound column but an exception is thrown with the
message:
"Specified cast is invalid."
when the "Enabled" column in the first row is being processed. I have tried
things such as:
<asp:CheckBox runat="server" Checked='<%# ((int)DataBinder.Eval(Container,
"DataItem.Enabled"))==1 %>'>
and
<asp:CheckBox runat="server" Checked='<%# (((int)DataBinder.Eval(Container,
"DataItem.Enabled"))==1)? true : false %>'>
without any success.
Any suggestions would be appreciated.