User Control design Question

  • Thread starter Thread starter Andrea Williams
  • Start date Start date
A

Andrea Williams

I have several User Controls and I will need to fill some of the Web Form
Controls in them with data from the database. So here's the question:

Should I write the code to bind a RadioButtonList control to a dataset
inside the code-behind for the UserControl?
or
Should I create a method called something like 'BindDataSet' to pass the
Data Set to the User control and then bind the control in the method?

I'm thinking that it might be better with the latter b/c it would make the
User Control more reusable for other projects.

Is there another way that I'm not thinking of right now? Any other
thoughts?

Thanks in advance!
Andrea
 
I would be inclined to put this in the code-behind for the user control for
maintainability - but you could, in turn, call a method in an external class
from the code-behind to actually get the data, which might be how you make
it more re-usable.
 
Andrea,

The sad truth is that you cannot re-use User Controls
in other projects.

You may find yourself cutting and pasting html in order
to simulate this.

Anyway, I think you still want to lean in the direction of the second
scenario. It's a good idea to keep all the database stuff in a separate
class -- the fewer places you make the database call the better. You
might have a business layer class on top of this with a method like
'GetEmployees' that would return a dataset or collection that you could
bind to different controls.

I typically do the binding itself in the code-behind for the User
Control.

HTH,
Jim
 
Back
Top