Setting multiple property values in one databind

J

John

If I have aspx code like:

< asp:label Text='<%# GetData() %>'>< /asp:label>

Is there some way in my GetData() method that I can get a handle to this
Label control, and set other properties apart from Text, too??

That way a single db addess could set text, color, visibility etc.

Passing 'this' just returns the asp:page control :(

Thanks,

John

PS. I may have asked this before, but can't find the message anywhere!
 
J

John Saunders

John said:
If I have aspx code like:

< asp:label Text='<%# GetData() %>'>< /asp:label>

Is there some way in my GetData() method that I can get a handle to this
Label control, and set other properties apart from Text, too??

It wouldn't be a good idea for GetData to know what control it's binding to,
so it wouldn't be a good idea for it to set any properties at all, much less
to set more than one property.

What about:

<asp:Label Text='<%# GetData()["Text"] %>' ForeColor='<%# GetData["Color"]
%>' />
 
E

Eliyahu Goldin

John,

Yes you can do this, and it is perfectly ok.

Add DataBinding event to your Label control and make GetData () the event
handler. It will get parameter "sender" which is the reference to the
control originated the event. In this way you can use the same GetData()
method for many controls and access as many control properties as you wish.

Eliyahu

The trick
 

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

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top