This is a migrated thread and some comments may be shown as answers.

Question about using a single combo control with different data source

2 Answers 61 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 31 Aug 2010, 02:52 PM
Hi,

I'm trying to come up with a generic approach in setting the data resources for the combo box.  Instead of always setting the following properties:

prioritylist.DataSource = "";
           prioritylist.DataValueField = ARConstants.PriorityListName;
           prioritylist.DataTextField = ARConstants.PriorityListId;            
           prioritylist.DataBind();
           prioritylist.Items.Insert(0, new ListItem("", "0"));
           prioritylist.SelectedIndex = 0;

In my code behind, I'd like to pass the control and since I always know that my datasource will alway have id and name.  I want the call to be a single instance.

I have a controller class call DDLController that does the following:
public void LoadLookup(Page page, DropDownList ddlPriority, DropDownList ddlRM, DropDownList ddlBSE, DropDownList ddlDataType)
       {
           LoadPriorityList(page,ddlPriority);
           LoadRFMList(page, ddlRM);
           LoadBSEList(page, ddlBSE);
           LoadSystemList(page, ddlDataType);
       }
       private void LoadPriorityList(Page page,DropDownList prioritylist)
       {
           prioritylist.DataSource = "";
           prioritylist.DataValueField = ARConstants.PriorityListName;
           prioritylist.DataTextField = ARConstants.PriorityListId;            
           prioritylist.DataBind();
           prioritylist.Items.Insert(0, new ListItem("", "0"));
           prioritylist.SelectedIndex = 0;
       }
       private void LoadRFMList(Page page, DropDownList rfmlist)
       {
           rfmlist.DataSource = "";
           rfmlist.DataValueField = ARConstants.RFMId;
           rfmlist.DataTextField = ARConstants.RFMName;            
           rfmlist.DataBind();
           rfmlist.Items.Insert(0, new ListItem("", "0"));
           rfmlist.SelectedIndex = 0;
       }
As you can see above I created 2-3 separate methods that will render the different combo box.  However this methodology seems to redunant where I want to render the control only once.  I'm not really sure how to make this generic.  Any help on this design would be very helpful.

Thanks,

2 Answers, 1 is accepted

Sort by
0
Jani
Top achievements
Rank 1
answered on 03 Sep 2010, 08:45 AM
Hello,

I see that you're using DropDownList, so I guess you should post this question in the asp.net forums.
0
Joe
Top achievements
Rank 1
answered on 03 Sep 2010, 12:37 PM
Hi,

Actually this is a telerik drop down not a drop down.  I'm looking more at the concept of reducing redunancy in make the same calls over and over.

Thank You,
Tags
ComboBox
Asked by
Joe
Top achievements
Rank 1
Answers by
Jani
Top achievements
Rank 1
Joe
Top achievements
Rank 1
Share this question
or