this is a great way to reduce code in an asp.net form. using a user control, which encapsulates all the functionality of the dropdownlist, including the data binding (sqldatastource or objectdatasource).
here's the sample code for the ascx file:
until now, it's all normal. what we add to make it the user control a DropDownList is a property to the ascx.cs file of this user control for the code behind (ascx.cs) file:
This property gives access to the dropdownlist, directly from the user control. Combining all these (the property SelectedValue in the code behind file and the ascx, we can have the following two line to define are dropdownlist:
the above code is a lot cleaner and developer friendly than having the sqldatasource syntax included in every page. This method is just simpler than using a custom control, although the ideal is always a custom control in the bin folder.
Here's a screen shot of what the dropdownlists folder looks like in one of the applications where this technique is applied :