Click here to Skip to main content
Rate this: bad
good
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 asp.net 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" />
                    <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 23-May-12 1:37am

1 solution

Rate this: bad
good
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:templatefield>
  <itemtemplate>
  <asp:checkbox id="chkOnlineCheck" runat="server" checked="<%# Eval("ONLINE_CHECK").ToString() == "0" ? false : true) %>" />' />
  </itemtemplate>
</asp:templatefield>
 
Regards,
Gerald
  Permalink  
v2
Comments
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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 510
1 CPallini 330
2 OriginalGriff 225
3 George Jonsson 120
4 ChauhanAjay 104
0 OriginalGriff 6,474
1 Sergey Alexandrovich Kryukov 6,190
2 CPallini 5,180
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 23 May 2012
Copyright © CodeProject, 1999-2014
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