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

Checkbox gives error while Inserting new Record

4 Answers 146 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tariq
Top achievements
Rank 1
Tariq asked on 14 Jul 2008, 10:31 AM
I have a GridCheckBoxColumn in my RadGrid. This column is bound to "Bit" type field in the SQL Server.  I can sucessfully Insert and Edit the item in In-Place and Auto Generated Form Type modes. 

However when I use Template in EditFormType then I can only Edit the item succssfully, but Insert throws an exception as shown below:

The Exception points to this block of code:

<
asp:CheckBox ID="CheckBox1" runat="server" DataType="System.Boolean" Checked="<%# Bind('IsActive') %>" />

The Exception box contains this text:

InvalidCastException was unhandled by user code
Specified cast is not valid

I would assume that when the Item is called for Editing the bound field has either True or False as its value. However upon Insertion the bound field is NULL at that stage, and therefore the Checkbox throws this exception.  This is just my assuption and could be wrong.

Please guide me how to fix this problem.

Tariq

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2008, 11:46 AM
Hi Tariq,

Try binding the CheckBox as shown below.

ASPX:
<asp:CheckBox ID="CheckBox1" Checked='<%# Eval("IsActive") %>' runat="server" /> 


Thanks
Shinu.
0
Tariq
Top achievements
Rank 1
answered on 14 Jul 2008, 01:50 PM

I changed Bind to Eval as shown by you but still getting exactly the same error that says:

InvalidCastException was unhandled by user code
Specified cast is not valid


The error message is still pointing to the Checkbox definition in the Template form that now contains Checked='<%# Eval("IsActive") %>'

By the way is there a way to attach screen shots to forum messages?

Tariq

0
Pablo
Top achievements
Rank 1
answered on 02 Aug 2008, 05:31 PM
Hello.
Did you ever solved this problem?
How?
I am having exactly the same situation.

Thanks a lot!
0
Yavor
Telerik team
answered on 04 Aug 2008, 05:11 AM
Hello Pablo,

To see more information along the lines of the requested functionality, please refer to the following forum post.
I hope it helps.

Kind regards,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Tariq
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Tariq
Top achievements
Rank 1
Pablo
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or