Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
835
WebDropDown Deployment
posted

Can I still add items to the dropdown programmatically instead of using the DataSource? I hope I get a reply ASAP. Thanks.

  • 10685
    Suggested Answer
    Offline posted

    Hello Andrea, 

    Preffered approach is to set a DataSource and use DataBind method. Of cource, it is also possible to just add the DropDown Items manually in the markup OR well in the code behind, like: 

    Markup:
               <ig:WebDropDown ID="WebDropDown1" runat="server" Width="200px">
                <Items>
                    <ig:DropDownItem Selected="True" Text="Item1" Value="">
                    </ig:DropDownItem>
                    <ig:DropDownItem Selected="False" Text="Item2" Value="">
                   </ig:DropDownItem>
                    <ig:DropDownItem Selected="False" Text="Item3" Value="">
                    </ig:DropDownItem>
                </Items>
           </ig:WebDropDown>

    Code Behind:
                //adding Items from Code Behind to WebDropDown created in Markup with ID= WebDropDown1
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some Text", Value = "1"});
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some Other Text", Value = "2" });
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some More Text", Value = "3" }); 

    Or Create all inCodeBehind: 

    if (!IsPostBack)
            {
                DropDownProvider provider = new DropDownProvider();
                provider.ID = "dropdown1";
                provider.EditorControl.DropDownContainerWidth = 150;
                WebDataGrid1.EditorProviders.Add(provider); 
                //Could Use the DataSource as well
                ArrayList myAL = new ArrayList();
                myAL.Add("Hello");
                myAL.Add("World"); 

                //Creating WebDropDown and adding Items From Code Behind
                WebDropDown DD = new WebDropDown();

                //Could Use the DataSource as well
                //DD.DataSource = myAL;

                DD.ID = "CodeBehindDD";
                DD.Width = 200;
                DD.Items.Add(new DropDownItem() { Text = "CodeBehindDD", Value = "1" });
                DD.Items.Add(new DropDownItem() { Text = "CodeBehindDD Text", Value = "2" });
                DD.Items.Add(new DropDownItem() { Text = "CodeBehindDD More Text", Value = "3" });
                this.form1.Controls.Add(DD); 

                //adding Items from Code Behind to WebDropDown created in Markup with ID= WebDropDown1
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some Text", Value = "1"});
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some Other Text", Value = "2" });
                WebDropDown1.Items.Add(new DropDownItem() { Text = "Some More Text", Value = "3" });
            } 

    I am attaching a runnable codeSample in order to better illustrate the possibilities when defining a WebDropDown Items.

    WDG_DropDownProvider_CodeBehind_MoreDropDownsCodeBehind.zip
  • 10685
    Offline posted

    I am checking about the progress of this issue. Please let me know if you need any further assistance on this.

  • 10685
    Offline posted in reply to Andrea Minoza

    Hello Andrea,

    I could not fully understand what you mean, and yet I believe this is regarding the same issue discussed at: http://www.infragistics.com/community/forums/t/90694.aspx?PageIndex=2 , where my colleague Maya has offered a solution for this particular asking. 

    In general, it is consider best practice to open a new forum thread for any new issue. What is more, this is in order to better navigate via the topics discussed and help the community users to find solutions faster and easier.  

    Please let me know if you have further questions regarding “add items to the dropdown” original asking! 

    Thank you for choosing Infragistics components!