Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview with some boundfield columns to my data source. I have also a checkboxfield that I want checked it if it recieves a particular integer value (1) for example and unchecked it for (0). because I have a problem already that Oracle doesn't have a boolean type and asp.net depending on boolean to mark the checkbox. Please help


ASP.NET
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                    AutoGenerateColumns="False" CellPadding="4" 
                    DataSourceID="ObjectDataSource1" GridLines="None" 
                    onselectedindexchanged="GridView1_SelectedIndexChanged" PageSize="25" 
                    Height="402px" Width="818px" ForeColor="#333333" AllowSorting="True">
                    <PagerSettings FirstPageText="first" LastPageText="last" 
                        Position="TopAndBottom" Mode="NumericFirstLast" />
                    <RowStyle BackColor="#EFF3FB" />
                    <Columns>
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="APPLICATION_NO" HeaderText="Application No." 
                            SortExpression="APPLICATION_NO" >
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="SNAME" HeaderText="Name" 
                            SortExpression="SNAME" />
                        <asp:BoundField DataField="NATIONALITY" HeaderText="Nationality" 
                            SortExpression="NATIONALITY" >
                            <HeaderStyle HorizontalAlign="Left" />
                        </asp:BoundField>
                        <asp:BoundField DataField="APPLICATION_DT" HeaderText="Created Date" 
                            SortExpression="APPLICATION_DT" />
                            <asp:CheckBoxField DataField="ONLINE_CHECK" HeaderText="flag" SortExpression="ONLINE_CHECK" />
                    </Columns>
                    <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
                    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" 
                        Font-Bold="True" Font-Size="Medium" />
                    <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                    <EditRowStyle BackColor="#2461BF" />
                    <AlternatingRowStyle BackColor="White" />
                </asp:GridView>
Posted

1 solution

I would go so far as to say, that you can only bind a boolean to an asp:CheckBoxField.

However you can use a asp:TemplateField and convert the value in the markup to pass it to an asp:CheckBox you could also do that in the DataBound event.

Make sure to catch the event before adding and editing a row, so you can correctly read the value from your checkbox and set the right datafield.

ASP
<asp:templatefield>
  <itemtemplate>
  <asp:checkbox id="chkOnlineCheck" runat="server" checked="<%# Eval("ONLINE_CHECK").ToString() == "0" ? false : true) %>" />' />
  </itemtemplate>
</asp:templatefield>


Regards,
Gerald
 
Share this answer
 
v2
Comments
kareem salem 27-May-12 3:36am    
It works very sucessfully!
thank you very much Gerald.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900