Control.DataBind()

T

TheGG

Control.DataBind() performs databinding for the current control and all child controls. How would I (within a Control subclass) _just_ perform databinding for the current control, and not the children?
 
T

Teemu Keiski

Hi,

Control (System.Web.UI.Control) itself does following in DataBind method.

1. Call base class's OnDataBinding
2. Checks if Controls collection is empty (it has child controls), if it
doesn't e.g it is empty then it just returns from the method
3. Sets Controls collection to be read-only
4. Iterates through Controls and calls dataBind for them one by one
5. Releases the Controls collection

And DataBind method is overridable/virtual so in a simple way you could just
override it and write the similar logic but do not loop through child
controls. That is...just call base class's OnDataBinding and return from the
method. Certainly you need also to do/specify how you want to perform
databinding in the main control itself but that's another task. :)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke



TheGG said:
Control.DataBind() performs databinding for the current control and all
child controls. How would I (within a Control subclass) _just_ perform
databinding for the current control, and not the children?
 
T

TheGG

Great, thanks!

Teemu Keiski said:
Hi,

Control (System.Web.UI.Control) itself does following in DataBind method.

1. Call base class's OnDataBinding
2. Checks if Controls collection is empty (it has child controls), if it
doesn't e.g it is empty then it just returns from the method
3. Sets Controls collection to be read-only
4. Iterates through Controls and calls dataBind for them one by one
5. Releases the Controls collection

And DataBind method is overridable/virtual so in a simple way you could just
override it and write the similar logic but do not loop through child
controls. That is...just call base class's OnDataBinding and return from the
method. Certainly you need also to do/specify how you want to perform
databinding in the main control itself but that's another task. :)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke




child controls. How would I (within a Control subclass) _just_ perform
databinding for the current control, and not the children?
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top