[Download Sample Project]
Another feature that I thought to add is to simplify binding the collection to list controls, such as the DropDownList, RadioButtonList, etc. In order to do this, I added a method called BindToListControl that takes a reference to the list control the user wants to bind, sets its DataSource, DataTextField, and DataValueField properties appropriately, and calls the DataBind method on the control to bind the collection to the control.
Listing 3
1:
2:
3:
4:
5: public void BindToListControl(System.Web.UI.WebControls.ListControl list)
6: {
7: list.DataSource = this;
8: list.DataTextField = "Name";
9: list.DataValueField = "Value";
10: list.DataBind();
11: }