Label syntax question

  • Thread starter Thread starter msch-prv
  • Start date Start date
M

msch-prv

Sorry, I am a ASP.NET newbie.

Is it possible to chain args in a text attribute so that they don't
have to be re-initialized in a separate script? Ideally, given a
formview, I would like to concatenate different variables in a single
string:

<asp:FormView id="frm1" DataSourceID=".." Runat= ...>
<asp:Label ... Text='Tex1' & '<%# Bind("Var1") %>' & 'Text2' & '<%#
Bind("Var1") & ...' />

Is there a work-around?

TIA, Mark
 
Sorry, I am a ASP.NET newbie.

Is it possible to chain args in a text attribute so that they don't
have to be re-initialized in a separate script? Ideally, given a
formview, I would like to concatenate different variables in a single
string:

<asp:FormView id="frm1" DataSourceID=".." Runat= ...>
<asp:Label ... Text='Tex1' & '<%# Bind("Var1") %>' & 'Text2' & '<%#
Bind("Var1") & ...' />

Is there a work-around?

TIA, Mark

AFAIK, you could just write

Text='<%# "Tex1" + Bind("Var1") + "Text2" + Bind("Var1") + ...%>'

in C#. The problem is using one kind of quote on the outside and one on
the inside. I'm not familiar with the VB.NET syntax regarding quotes.

Anyhow, everything between <%# and %> is just a C#/VB.NET expression
that will be evaluated when DataBind() is called.
 
ASP.Net is object-oriented, unlike ASP. A Label is an object. You've got to
think of it as an object, and set its properties.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Sequence, Selection, Iteration.
 
Thanks for the reply.

The following works in VB:
Text='<%#"Test1" & " Test2"%>'

This one fails:
Text='<%#"Test1" & " Test2" & Cstr(Bind("ActFrom")) %>'

Does someone have an idea to make it work in VB? Thanks for any
suggestions, Mark
 
Kevin, can you explain further?

Is..

Text=<%# Bind("Var1") %>'

saying: "when you bind, put the Var1 value in the Text property of this
object, rather than saying "evaluate this expression"???
 
If you're using DataBinding, it depends on what you're DataBinding to. It's
hard to tell from your post, but it looks like it's being bound to a
property or field. You can certainly either change the property or field
it's bound to, or use a property with a getter that does the work and bind
to that.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Sequence, Selection, Iteration.


cannontrodder said:
Kevin, can you explain further?

Is..

Text=<%# Bind("Var1") %>'

saying: "when you bind, put the Var1 value in the Text property of this
object, rather than saying "evaluate this expression"???
 

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

Back
Top