tags:

views:

37

answers:

2

Hi..

I just wanted to confirm couple of things.

I) Code snippet:

cmb1.Datasource= dt;
cmb1.Valuemember = "value";

Does the control rendering happens 2 time for the control, 1 more time extra because of the value member getting changed after data source assigned. Is this so?

II) How can I trace these re-populations in C#? I just wanted to debug and see and confirm? Example please?

Thanks Karthik

A: 

This depends on the actual implementation of the data bound control. I'd expect a "good" control to only retrieve the data when it needs it, and therefore changing these properties would not do anything but clear out existing bindings (if there were any) and create the new ones without actually retrieving data.

You can use a profiler to trace such things, or bind to a class of yours and set a breakpoint or increase a counter.

Lucero
Its not re query db. Is it re rendering again because of value member chnaged?
karthik
Yes, if the data source triggers a change notification, it may redraw itself to reflect the change.
Lucero
A: 

I) It depends. If this is for an asp.net site, you have to also call the DataBind() method before anything actually happens. But otherwise, yes - databinding will likely happen twice.

II) You can trace it by building a method that returns a datatable, and binding to that method as the data source. Then you can set a breakpoint inside the method and watch for when the breakpoint is hit.

Joel Coehoorn
I followed as per your suggestion, Only once getting called.At the time of value member change It will re populate to control right?
karthik
No, it will not repopulate the control.
Joel Coehoorn