We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get selected values from code behind?

Thread ID:





119307 Jun 3,2015 09:19 PM UTC Jun 5,2015 05:25 AM UTC ASP.NET Web Forms 3
Tags: DropDownList
megan brown
Asked On June 3, 2015 09:19 PM UTC

I can get the indexes of the selected items, but I want to get the values of the selected items.  How do I get the values?

code behind:
        //this gets the index of the selected items
        foreach (int item in brandSelect.SelectedItems)


<ej:DropDownList ID="brandSelect" runat="server" DataTextField="Brands" ShowCheckbox="true"></ej:DropDownList></span>

Ezhil S [Syncfusion]
Replied On June 4, 2015 12:07 PM UTC

Hi Megan,

Thank you for contacting Syncfusion support.

In order to get the Selected items value of a DropDownList control in code behind on a post back, we suggest you to use the Text property of the DropDownList control. In code behind you can get all the selected items value separated with a delimiter(,), if you want to get the items individually then using Split() method for DropDownList.Text property will return you a collection of selected item values separately. Please refer the following code snippet,

    <ej:DropDownList ID="brandSelect" runat="server" DataIdField="ID" DataTextField="Text" ShowCheckbox="true"></ej:DropDownList>

    <br />

    Selected value after post back: <br />

    <asp:Label runat="server" ID="lbl" ></asp:Label><br /> <%--label value updated after post back--%>

<asp:Button Text="PostBack" runat="server" ID="btn1" OnClick="btn1_Click" />

        protected void btn1_Click(object sender, EventArgs e)


            lbl.Text = "";

            foreach (string val in brandSelect.Text.Split(','))


                lbl.Text += val+" , "; // set the label text with selected items value


Download the sample prepared from the link below:

Please let us know if you have any other queries.

Ezhil S

megan brown
Replied On June 4, 2015 03:36 PM UTC

Thanks.  Since I want the value and the not the text, I changed your code to:

        foreach (string val in brandSelect.Value.Split(','))
            //do something

And this worked.

Ezhil S [Syncfusion]
Replied On June 5, 2015 05:25 AM UTC

Hi Megan,

Thanks for the update.

We are glad that the suggested solution worked to met with your requirement.

Please let us know if you have any other queries.

Ezhil S


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon