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

RadGrid And CheckBox

1 Answer 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
johnson lim
Top achievements
Rank 1
johnson lim asked on 19 Mar 2010, 08:02 AM
Hi,
i have a radgrid which has 1 checkbox inside.
It work fine if i edit or delete the record in the radgrid but error come out when i want to add data in the radgrid

Below is my coding
 
<ajax:GridTemplateColumn  UniqueName="GCStatus" Headertext="Active" SortExpression ="Active"
                    <ItemTemplate > 
                         <asp:CheckBox runat="server" ID ="chkActive" Checked='<%# DataBinder.Eval(Container.DataItem, "Active") %>'  Enabled =false />     
                    </ItemTemplate> 
                    <EditItemTemplate > 
                     
                        <asp:CheckBox runat="server" ID ="chkActive" Checked='<%# DataBinder.Eval(Container.DataItem,   "Active" ) %>'  /> 
                     
                    </EditItemTemplate> 
                </ajax:GridTemplateColumn> 



The error is as below
Conversion from type 'DBNull' to type 'Boolean' is not valid.

Does anyone has idea on how to eliminate this error?




1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Mar 2010, 10:36 AM

Hi Johnson,

Try the following settings for CheckBox Checked property.

ASPX:

 
    <telerik:GridTemplateColumn UniqueName="GCStatus" HeaderText="Active or Not" SortExpression="MartalStatus">  
        <ItemTemplate>  
            <asp:CheckBox runat="server" ID="chkActive" Checked='<%# DataBinder.Eval(Container.DataItem, "Active") %>'  
                Enabled="false" />  
        </ItemTemplate>  
        <EditItemTemplate>  
            <asp:CheckBox runat="server" ID="chkActive" Checked='<%# (DataBinder.Eval(Container.DataItem,"Active") is DBNull ?false:Eval("Active")) %>' />  
        </EditItemTemplate>  
    </telerik:GridTemplateColumn> 

-Shinu.

Tags
Grid
Asked by
johnson lim
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or