This is a migrated thread and some comments may be shown as answers.

NullException with Boolean Checkbox in ItemTemplate

1 Answer 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 28 Jun 2014, 06:35 AM
Hi,

I just want to bind a simple boolean to a checkbox, but it isn't working.
All tries to get the bool into the grid will be answered with a NullException ... but why??

A first chance exception of type 'System.NullReferenceException' occurred in App_Web_patoy0yq.dll


    <telerik:RadGrid ID="RadGrid1" runat="server" Culture="de-DE" ShowStatusBar="True" AllowPaging="True" PageSize="5" Width="800px"
        DataKeyValues="Id, ModuleName, IsActive, NavigationPath" OnItemCommand="RadGrid1_ItemCommand" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
        <MasterTableView Width="100%" AutoGenerateColumns="False" CommandItemDisplay="Top" DataKeyNames="Id, ModuleName, IsActive, NavigationPath" EditMode="PopUp"
            NoDetailRecordsText="Keine Detaileinträge." NoMasterRecordsText="Keine Einträge." RetrieveNullAsDBNull="False">
            <Columns>

                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" ItemStyle-Width="30px">
                    <ItemStyle Width="30px"></ItemStyle>
                </telerik:GridEditCommandColumn>

                <telerik:GridBoundColumn DataField="Id" DataType="System.Guid" HeaderText="Modul Id" ReadOnly="true"
                    SortExpression="ModuleId" UniqueName="ModuleId">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text=""></ModelErrorMessage>
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>

                <telerik:GridBoundColumn DataField="ModuleName" DataType="System.String" HeaderText="Modul Name"
                    SortExpression="ModuleName" UniqueName="ModuleName">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text=""></ModelErrorMessage>
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>

                <%--<telerik:GridCheckBoxColumn DataField="IsActive" HeaderText="Modul aktiviert"
                    SortExpression="ModuleIsActive" UniqueName="ModuleIsActive">
                </telerik:GridCheckBoxColumn>--%>      <%-- Tried this, but no values (always FALSE) --%>

                <telerik:GridTemplateColumn HeaderText="IsActive" UniqueName="TemplateColumn">
                    <EditItemTemplate>
                        <asp:CheckBox ID="editChkBox" runat="server"
                            Checked='<%# Bind("IsActive") %>'></asp:CheckBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="defaultChkBox" runat="server"
                            Checked='<%# Eval("IsActive") %>'></asp:CheckBox>    <%-- << NullException here! --%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

                <telerik:GridBoundColumn DataField="NavigationPath" DataType="System.String" HeaderText="Modul Navigationspfad"
                    SortExpression="ModuleNavigationPath" UniqueName="ModuleNavigationPath">
                    <ColumnValidationSettings>
                        <ModelErrorMessage Text=""></ModelErrorMessage>
                    </ColumnValidationSettings>
                </telerik:GridBoundColumn>

                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton" ItemStyle-Width="30px">
                    <ItemStyle Width="30px"></ItemStyle>
                </telerik:GridButtonColumn>

            </Columns>

        </MasterTableView>

        <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="true"></Selecting>
        </ClientSettings>
    </telerik:RadGrid>


I just want to get a bool .... !!! ??????

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Jun 2014, 04:46 AM
Hi Frank,

Your code works fine at my end. To display a boolean value you can use GridCheckBoxColumn. Bind this column type to a Boolean field by setting its DataField property. If this column type is bound to a data value that is not Boolean, the grid throws an exception.When the grid is in browser mode, or if the column is read-only, the check box is disabled. When the column is editable, the check box is enabled.
Make sure that the column contains a True/False value and not null in DB.

Thanks,
Princy
Tags
Grid
Asked by
Frank
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or