Hi
The control has some new argument over the dropdown list. There is a new property called DataGroupField. When we are binding the data then we need to asign the value of the group field. Also the data need to be sorted on the group itself otherwise the same group will be show twice (I have not added sorting of the data based on the group in the control as yet. But waiting to see if this will be required.).
You can also add the items one by one. In this case you need to provide the group of the item also. The add methods take and object of type OptionListItem. The optionListItem takes three argument, ItemName, Value and the group. (I know you will have the question why not the type ListItem. The reason is ListItme type can track only the name and value. To add the group I had to create a new type.)
The control also keeps track of its items (which also includes the group.).
To use the control download the provided dll. Add the reference to the dll in the project. Now you need to register the control in the page.
<%@ Register Assembly="OptionCtrl" Namespace="VikServerControl" TagPrefix="cc1" %>
You can add the control to the page with the following directive.
<cc1:OptionDropDownList id="OptionDropDownList1" runat="server"></cc1:OptionDropDownList>
Now you can add the items in the code behind (The support for adding the items in HTML designer is not there as yet.). In the code behind we can either add the items one by one using the Items.Add method.
OptionDropDownList1.Items.Add(new VikServerControl.OptionListItem(dt.Rows[i]["Text"].ToString(), dt.Rows[i]["Value"].ToString(), dt.Rows[i]["Group"].ToString()));
Or we can databind the Items to the control. If you are using the databind method do not forget to provide the DataGroupField value. DataGroupField will the the column name for the data of the Group. if the value for the DataGroupField is not provided then the value of the text is taken as the Group name.
OptionDropDownList1.DataGroupField = "CategoryName";
OptionDropDownList1.DataTextField = "ProductName";
OptionDropDownList1.DataValueField = "ProductID";
OptionDropDownList1.DataSource = ds.Tables[0];
OptionDropDownList1.DataBind();
You can also get the selectedIndexChanged event for the control. This works same as the dropdown list or Listbox. The list box control for the same is alos available for the same. The listbox control allows multiple selection also (as usual controlled by the property SelectionMode).
Here is the Link to the download of the dll Download
Thanks
Vikram
P.S. Do not hesitate to use the control and give any feed back.