Reputation: 32500
I have a template field within a GridView to display a checkbox in edit view and some custom text in normal view.
The results of the query to populate the grid are coming back in a DataSet.
In the edit view I can't get the checkbox to accept the column that is retuning from the DataSet (which is in T/F format) as it says its not the correct type. Even if I return "true" or 1 in the column it still dosn't work.
I take it I need to convert but can't get the syntax correct in this context
<EditItemTemplate>
<asp:CheckBox ID="cbPostToFarm" runat="server" Checked='<% Bind("BOOL_COL")' />
</EditItemTemplate>
Upvotes: 0
Views: 7536
Reputation: 8999
You were so close! Just missing the # and the ending %>
<EditItemTemplate>
<asp:CheckBox ID="cbPostToFarm" runat="server" Checked='<%# Bind("BOOL_COL") %>'/>
</EditItemTemplate>
Note that the use of single quotes after Checked and not Double Quotes is important. You will get errors with double quotes.
Upvotes: 1
Reputation: 161
This seems working for me (.net Visual Studio 2010)
<asp:TemplateField HeaderText="Ordered" SortExpression="Ordered">
<ItemTemplate>
<asp:CheckBox ID="ID_CKBOX" runat="server"
Checked='<%#Eval("ordered") %>' />
</ItemTemplate>
<ItemStyle Width="8px" />
</asp:TemplateField>
Where 'ordered' is the one of the db field of select statement.
Upvotes: 1
Reputation: 32500
I got round the issue by not binding directly to the dataset but creating a strongly typed list.
I'm sure there must be a syntactical trick to get the checkbox to bind directly to a DataSet but for the sake of a simple type I gave up looking.
Upvotes: 0
Reputation: 7539
Use the GridView DataBound event to set the value. Inside of the DataBound event:
Ensure the row you are working with is not a Header/Footer row.
Create a reference to the CheckBox.
Create a reference to the data that is being bound.
Mark the CheckBox checked when appropriate.
Upvotes: 1