473,326 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How do I do data binding with a checkbox?

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)
Nov 19 '05 #1
1 1421
>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)
Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alan Silver | last post by:
Hello, I'm trying to use an ArrayList to do data binding, but am getting an error I don't understand. I posted this in another thread, but that was all confused with various other problems,...
6
by: Alan Silver | last post by:
Hello, I am data binding a repeater that has a checkbox in the ItemTemplate. The data value coming out of the database is a char(1) field containing either "y" or "n". I want to use this value...
0
by: Tom Wing | last post by:
I'm looking for some help with a data binding problem. I'm not able to bind a checkbox from a dataset to an Access mdb. Regardless of the databinding property I set the checkbox to the...
0
by: Larry Serflaten | last post by:
I am not sure how many are aware of this sort of data binding, but as it is new to many (classic) VB developers I thought I would post this once just to let people know of its availablility. ...
14
by: Rolf Welskes | last post by:
Hello, I have an ObjectDataSource which has as business-object a simple array of strings. No problem. I have an own (custom) control to which I give the DataSourceId and in the custom-control...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.