Mark Rae said:
<asp:TemplateField>
<ItemTemplate>
<%# Convert.ToBoolean(Eval("MyBitField")) ? "Yes" : "No" %>
</ItemTemplate>
</asp:TemplateField>
Tried that but get:
Object cannot be cast from DBNull to other types.
Also, for editing the row, I do the following in my code:
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
chkReviewed =
(CheckBox)e.Row.FindControl("chkReviewed");
if (chkReviewed != null)
chkReviewed.Checked = ((drv["Reviewed"] !=
DBNull.Value && (bool)drv["Reviewed"]) ? true : false);
}
}
Can I also put this in the GridView, where I set the checkbox based on the
data in the ItemTemplate. Above I use the DataView that is passed - which
works fine. I am just interested to see if I can do it in the GridView
itself. There are cases where I may have 4 or 5 columns of checkboxes and
it would be nice to just put it in the markup:
<asp:TemplateField HeaderText="Reviewed"
ItemStyle-CssClass="alignCenter" SortExpression="Reviewed" Visible="True">
<ItemTemplate >
<asp:Label ID="lblReviewed" runat="server" Text='<%#
Convert.ToBoolean(Eval("Reviewed")) ? "Yes" : "No" %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Checkbox ID="chkReviewed" runat="server"></asp:Checkbox>
</EditItemTemplate>
</asp:TemplateField>
Thanks,
Tom