Asp.net DropdownList Va;ues and items

Hi ,
    i am using bellow Dropdown list with values and items ,

 <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem  Value="Red">A1</asp:ListItem>
      <asp:ListItem  Value="green">A2</asp:ListItem>
    <asp:ListItem Value="blue">A3</asp:ListItem>
    <asp:ListItem Value="Red">A4</asp:ListItem>
      <asp:ListItem Value="green">A5</asp:ListItem>
      <asp:ListItem Value="blue">A6</asp:ListItem>
      <asp:ListItem Value="Red">A7</asp:ListItem>      
      <asp:ListItem Value="green">A8</asp:ListItem>      
      <asp:ListItem Value="blue">A9</asp:ListItem>
      <asp:ListItem Value="Red">A10</asp:ListItem>
      <asp:ListItem Value="green">A11</asp:ListItem>
    <asp:ListItem Value="blue">A12</asp:ListItem>
        </asp:DropDownList>

Using this Drop down list ,i retrieving the data at code behind . if i select A12 on dropdown list and i retrieving at  code behind "DropDownList1.SelectedItem.Tosting()" it shows A3 and i select A8 shows A2 and i select  A10 shows A1. I found the reason why it was happening means it selecting the top value of selected value item . Can any one help me how to select respective item with values ..
CPSRIAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ajay SharmaCommented:
To get the right text always use DropDownList1.SelectedItem.SelectedItem.Text

Also are using postabacks to show the value?

If possible post your page's code.
0
Pratima PharandeCommented:
you need to have unique values for each item
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Navneet.Net Full Stack DeveloperCommented:
Hi!

Your values are same it has to be unique
else it will take the first encountered values.

Thanks!
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

CPSRIAuthor Commented:
ajaysharmaapjs, here is my page's code -
 protected void DropDownList1_TextChanged1(object sender, EventArgs e)
    {
        string strItem = DropDownList1.SelectedItem.Value.ToString();
        Response.Write(strItem);
    }

pratima_mcs, if i have unique values, it will not work out for me.
0
Ajay SharmaCommented:
Any specific reason you are using the _TextChanged event, if not then use DropDownList1_SelectedIndexChanged event
0
santhimurthydCommented:
Problem is with your Drop down declaration

<asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Value="Red">A1</asp:ListItem>
      <asp:ListItem  Value="green">A2</asp:ListItem>
    <asp:ListItem Value="blue">A3</asp:ListItem>
    <asp:ListItem Value="Red">A4</asp:ListItem>
      <asp:ListItem Value="green">A5</asp:ListItem>
      <asp:ListItem Value="blue">A6</asp:ListItem>
      <asp:ListItem Value="Red">A7</asp:ListItem>      
      <asp:ListItem Value="green">A8</asp:ListItem>      
      <asp:ListItem Value="blue">A9</asp:ListItem>
      <asp:ListItem Value="Red">A10</asp:ListItem>
      <asp:ListItem Value="green">A11</asp:ListItem>
    <asp:ListItem Value="blue">A12</asp:ListItem>
        </asp:DropDownList>


when every you select any item in your drop down, the behind it will considered the selected value to identify the item at code behidn and teh first occurs is the answer.
So when you select "A12" the value selected is "Blue"  which is the "A3" value and thus you will get the third item.

To over comegive Unique value for the listitems

this link will help you take a decision
http://social.msdn.microsoft.com/Forums/en-US/vblanguage/thread/a279e6f5-f0b1-4afc-a53f-22becf608892
0
CPSRIAuthor Commented:
Thank you ,  now i am clear about the drop down list.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.