Question about using a single combo control with different data source

3 posts, 0 answers
  1. Joe
    Joe avatar
    48 posts
    Member since:
    Mar 2009

    Posted 31 Aug 2010 Link to this post

    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. Jani
    Jani  avatar
    3 posts
    Member since:
    Jan 2010

    Posted 03 Sep 2010 Link to this post

    Hello,

    I see that you're using DropDownList, so I guess you should post this question in the asp.net forums.
  3. Joe
    Joe avatar
    48 posts
    Member since:
    Mar 2009

    Posted 03 Sep 2010 Link to this post

    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,
Back to Top