Link to home
Get AccessLog in
Avatar of forsters
forstersFlag for United Kingdom of Great Britain and Northern Ireland

asked on

DataBinding CheckBox in FormView and show as checked/unchecked accordingly

Hi all,

I'd assumed this was straightforward but apparently not:

So firstly how do you databind a CheckBox in a FormView?
My FormView is Databound but I want my CheckBox to display as checked or unchecked based on the data already inserted (so this  is my edit view) therefore I need to tell the checkbox which field it's bound to but I can't see how!??

I'm very green in the realms of C# so I feel like I want to use an OnDatabinding event but I get as far as:  
protected void ChkBox_Bind(object sender, EventArgs e)

anyone able to help??
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Avatar of forsters

ASKER

Ah thank you so much, you know what I nearly tried that but because the default intellisense is just true/false I presumed it wasn't possible.

Just tried it now but I'm getting a "Specified Cast is not valid" error, any ideas why that might be?

My set up is slightly different in that I get to the FormView from a page which displays the integer value as a datafield in an asp:BoundField...is that the problem?
SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
just tried that with one of the check boxes and now that page errors too saying string was not recognised as a valid boolean...?

SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
its an integer (tinyint)
SOLUTION
Link to home
membership
This content is only available to members.
To access this content, you must be a member of Experts Exchange.
Get Access
Ahh that now works perfectly, thank you so much I've been looking everywhere to solve this.
Thats so simple now , brilliant thank you.

So just for my own understanding  I presume from your earlier question that the ChkBox control supports string, bit & bool datatypes?