将GridView中的CheckBoxField绑定到不支持布尔类型的Oracle [英] Binding CheckBoxField in GridView To Oracle That Doesn't support Boolean type

查看:58
本文介绍了将GridView中的CheckBoxField绑定到不支持布尔类型的Oracle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Gridview,其中有一些到数据源的boundfield列.我还有一个checkboxfield,如果要接收特定的整数值(1),我想对其进行检查,而对于(0),则不对其进行检查.因为我已经有一个问题,Oracle没有布尔类型和asp.net(取决于将复选框标记为boolean).请帮忙


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>

推荐答案

我什至可以说,您只能将布尔值绑定到asp:CheckBoxField.

但是,您可以使用asp:TemplateField并将标记中的值转换为将其传递给asp:CheckBox,也可以在DataBound事件中执行此操作.

确保在添加和编辑行之前捕获事件,以便可以从复选框中正确读取值并设置正确的数据字段.

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


这篇关于将GridView中的CheckBoxField绑定到不支持布尔类型的Oracle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆