Setting multiple property values in one databind

  • Thread starter Thread starter John
  • Start date Start date
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!
 
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"]
%>' />
 
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
 
Back
Top