Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My dropdownlist always return me the value of first index no matter which value is selected.I'm not populating data on page load is have provided values in list-item .
and not giving the selecteditemvalues anyways
MY Code is.
C#
<pre> <asp:DropDownList ID="DropDownlistPriceSegmentC" runat="server" BackColor="#EBEAD2" Height="40px" Width="100%" EnableViewState="true">
                                                    <asp:ListItem Value="0">200</asp:ListItem>
                                                    <asp:ListItem Value="0">225</asp:ListItem>
                                                    <asp:ListItem Value="0">250</asp:ListItem>
                                                    <asp:ListItem Value="0">275</asp:ListItem>
                                                    <asp:ListItem Value="0">300</asp:ListItem>
                                                    <asp:ListItem Value="5">325</asp:ListItem>
                                                    <asp:ListItem Value="0">350</asp:ListItem>
                                                    <asp:ListItem Value="0">375</asp:ListItem>
                                                    <asp:ListItem Value="0">400</asp:ListItem>
                                                </asp:DropDownList>



What I have tried:

I have enable the view state of the dropdownlist.
Posted
Updated 14-Jan-18 19:44pm

1 solution

The Value attribute of all items (exxcept 325) is set to "0", so I'm not surprised that the value you get is always 0. Set the Value attribute for any item to something unique and identifiable.

[Edit]

Ah, so the index is always 0, not the value?

I would still try to change the 'Value' attributes. It's likely that ASP.NET derives the index based on the Value posted in the request (so, ASP.NET sees a Value of zero, performs indexing, and finds out that the first dropdownlist element has value zero, so the index is zero). If that's the case (and I think it is, because web browsers send the selected Value in a request, not the selected index), unique Values will lead to a correct index.
 
Share this answer
 
v2
Comments
Member 12237948 15-Jan-18 1:47am    
I'm but here the thing is i need text of that index as well along with the value.. only values don't matter.
Thomas Daniels 15-Jan-18 1:51am    
I see. Please see my edited answer.
Member 12237948 15-Jan-18 2:25am    
Thank After changing the values it works. Cheers !! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900