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

Binding CheckBox

1 Answer 89 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 09 Sep 2014, 03:16 PM
Hi Everyone,

I was following this Demo and run into a problem.  In the Web User Control(ascx) page, I need to Evaluate the CheckBox when editing a record.  When I click on Edit, it work great but when I click on "Add new record", I'm getting this error:

Error: Sys.WebForms.PageRequestManagerServerErrorException: Specified cast is not valid.

This is coming from the Checked function. Below is my coding.

<asp:CheckBox ID="chkbxReadOnly" runat="server"
              Checked='<%# DataBinder.Eval(Container, "DataItem.ReadOnly") %>'
             AutoPostBack="True" />

Can someone help me so  ignore the Checked function when I try to insert a record or modify the above Checked code?

1 Answer, 1 is accepted

Sort by
0
Anthony
Top achievements
Rank 1
answered on 09 Sep 2014, 04:47 PM
I feel so stupid for not thinking  of this before but I figure out the answer.  I just want to post it in case someone else run into this issue.

Checked='<%# DataBinder.Eval(DataItem, "ReadOnly") == DBNull.Value ? false : Convert.ToBoolean(DataBinder.Eval(DataItem, "ReadOnly")) %>'
Tags
Grid
Asked by
Anthony
Top achievements
Rank 1
Answers by
Anthony
Top achievements
Rank 1
Share this question
or