DropDownList Question

J

Just Me

Im sure there is a perfectly rational answer to this, I must be missing it
though. A dropdownlist with autopostback turned to 'true'. Notice in the
following list, items 0 and 1 valus are set to "0" and 2 and 3 are set to
"2".

If I select the last item, and it posts back, the third one get selected.
If item 0 was set to "1" and the rest were set to "0" and i selected items
1,2 or 3. Item 1 would get selected. Unless they are all different, it
seems that the first item which has a value not equal to those preceding it
is selected.

a.) Is this normal behaviour and why ?

b.) How can i get around this, as I was going to use the value to indicate
to the system that a particular item has a record associated with it.

<asp:ListItem Value="1" Text="Op1"></asp:ListItem>

<asp:ListItem Value="1" Text="Op2"></asp:ListItem>

<asp:ListItem Value="2" Text="Op3"></asp:ListItem>

<asp:ListItem Value="2" Text="Op4"></asp:ListItem>
 
J

Just Me

Actualy, I think I know the answer now.

When ASP.NET needs to reselect the option selected on postback, it only
knows the value and text for the ddl. So it must have to search through
until it finds the first item that matches it. This explains the seemingly
odd behavious I think.

So to get around it, I would have to prepend the value to the same value as
that in the text feild , this would give me a unique value but would enable
me to tag it.

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top