Why do labels have .DataBind ?

  • Thread starter Thread starter Roy
  • Start date Start date
R

Roy

This may seem silly, but I'm just curious...

I've noticed that in the code-behind, asp:Label has the .DataBind
property yet has NO corresponding .DataSource property? Am I missing
something? How can you databind something that has no datasource?

Thanks
 
You don't have to have DataSource in order to databind. All you need is to
use a databind expression for any of the control's properties. Example:

<asp:label ... Text='<%# CurrentDateString %>' ...

where CurrentDateString is a property you are binding your Text property to.
To get Text actually populated, you need to call the DataBind method.

Eliyahu
 

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