Re: How do I do data binding with a checkbox?

From: Alan Silver (alan-silver_at_nospam.thanx)
Date: 02/22/05


Date: Tue, 22 Feb 2005 20:52:04 +0000


>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(Container.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)


Relevant Pages