Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I do data binding with a checkbox?

Reply
Thread Tools

How do I do data binding with a checkbox?

 
 
Alan Silver
Guest
Posts: n/a
 
      02-21-2005
Hello,

I have a database table with a char(1) filed to indicate whether or not
an event is shown. If the value is 'y' it is, and if it's 'n' it's not.

I am trying to use this value in a checkbox (in a DataList), so that
when the value is 'y', the checkbox is checked, and when it's 'n', the
checkbox isn't checked.

I have tried ...

<asp:CheckBox ID="chkPhotosShow" Text=""Checked='<%#DataBinder.Eval(Container.DataI tem, "ShowEvent")=="y"?true:false%>' Runat="Server" />

which shows the checkbox, but never checks it.

Any ideas what I'm doing wrong? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
 
 
 
Alan Silver
Guest
Posts: n/a
 
      02-22-2005
>Any ideas what I'm doing wrong? TIA

I found an answer to this, so I'll post it here in case it's of use to
anyone.

The easiest way I found was to create a function :-

Boolean TrueIfY(string YN) {
if (YN == "y") {return true;}
else {return false;}
}

and use this in the ItemTemplate ...

<asp:CheckBox ID="chkPhotosShow" Text=""
Checked='<%#TrueIfY((string)DataBinder.Eval(Contai ner.DataItem,
"ShowEvent"))%>' Runat="Server" />

This worked fine. I still can't work out *why* this works when the
previous code didn't, as both ways you seem to be passing a Boolean
value. Still, at least it works

Hope this is of use to someone.

--
Alan Silver
(anything added below this line is nothing to do with me)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView binding - how to stop initial binding Amit ASP .Net 6 10-24-2006 08:06 AM
pywin32 COM sort in Excel (late binding fails, early binding works) (+py2exe) kogrover@gmail.com Python 2 10-20-2006 04:08 PM
Complex data binding question, binding child objects of a custom collection. JcFx ASP .Net Datagrid Control 0 06-01-2005 04:01 PM
Data Binding - using inline code vs. functions vs. straight binding Jordan ASP .Net 2 02-10-2004 08:32 PM
value binding and function binding Vivek Nallur Ruby 0 09-25-2003 02:52 AM



Advertisments