Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET ADO.NET Oracle
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 depending on boolean to mark the checkbox. Please help


<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" />
                        <asp:CommandField ShowSelectButton="True" />
                        <asp:BoundField DataField="APPLICATION_NO" HeaderText="Application No." 
                            SortExpression="APPLICATION_NO" >
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemStyle HorizontalAlign="Center" />
                        <asp:BoundField DataField="SNAME" HeaderText="Name" 
                            SortExpression="SNAME" />
                        <asp:BoundField DataField="NATIONALITY" HeaderText="Nationality" 
                            SortExpression="NATIONALITY" >
                            <HeaderStyle HorizontalAlign="Left" />
                        <asp:BoundField DataField="APPLICATION_DT" HeaderText="Created Date" 
                            SortExpression="APPLICATION_DT" />
                            <asp:CheckBoxField DataField="ONLINE_CHECK" HeaderText="flag" SortExpression="ONLINE_CHECK" />
                    <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" />

Posted 23-May-12 2:37am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:checkbox id="chkOnlineCheck" runat="server" checked="<%# Eval("ONLINE_CHECK").ToString() == "0" ? false : true) %>" />' />
kareem salem at 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)

Advertise | Privacy | Mobile
Web04 | 2.8.150301.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100