asp:Checkbox Text attribute-- how to do this?

J

Jim Bancroft

Hi everyone,

This is a silly one I'm sure, but I'm having a whale of a time putting some
text into my asp checkbox. Here's what I'd like to do:

<asp:CheckBox runat="server" Text='<%#DataBinder.Eval(Container.DataItem,
"OptionLabel")%> Fields' ID="chkDBFields"/>

....unfortunately, it doesn't work. The DataBinder text is evaluated
literally, so all I get on-screen is the word "Fields". And whenever I try
playing with the quotes I receive various syntax errors. Could someone show
me how to get this to work, so that I have my data-bound field and the word
"Fields" appended to it in the checkbox text? Thanks very much.
 
G

Guest

Hello,
You may want to try:

<asp:CheckBox runat="server" Text='<%#DataBinder.Eval(Container.DataItem,
"OptionLabel") & "Fields" %>' ID="chkDBFields"/>

I have not tried this in a checkbox, but it has worked for me in textboxes.

Regards,
Cesar
 
S

Shimon Sim

My experience that it will not work.The reason is that you have ranat
=server attribute.
You should use ItemDataBound event to write the text.
Shimon
 
J

Jim Bancroft

Thank you, Cesar. What I wound up doing was this:

<asp:CheckBox runat="server"
Text=<%#Convert.ToString(DataBinder.Eval(Container.DataItem, "OptionLabel"))
+ " Database Fields"/>

It's what worked for me. I hope someone can make use of it too.

-Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top