|
-
May 4th, 2005, 04:35 AM
#1
Thread Starter
Fanatic Member
Viewstate and autopostback
Heres the problem, that has taken me ages to spot. I have a databound dropdown box filled via a stored procedure. enabledviewstate is true as is autoPostback. When I select certain items in the dropdown, sometimes another item is selected instead. Here is the HTML of the dropdown
Code:
<select name="ddEntitys" onchange="javascript:setTimeout('__doPostBack(\'ddEntitys\',\'\')', 0)" id="ddEntitys">
<option value="%">All</option>
<option value="MR">A HAQUE </option>
<option value="CM">A & A SECURITY TECHNOLOGIES LTD </option>
<option value="LN">A & A SECURITY TECHNOLOGIES LTD </option>
<option value="WM">A & A SECURITY TECHNOLOGIES LTD </option>
<option value="WS">A & A A HARPER </option>
<option value="SW">A & A ACCIDENT REPAIR CENTRE LTD </option>
<option value="EM">A & A BUSINESS MACHINES (SERVICE) LTD </option>
<option selected="selected" value="ES">A & A COWAN </option>
<option value="LV">A & A DONE </option>
<option value="SL">A & A MARIS </option>
<option value="SM">A & A MEATS LTD </option>
<option value="EA">A & A MOTOR ENGINEERS </option>
<option value="ES">A & A STURROCK </option>
<option value="WS">A & A TAYLOR </option>
<option value="CM">A & A YOUSAF </option>
<option value="WM">A & A.K. BUTTERWORTH LTD </option>
<option value="WN">A & B AIR SYSTEMS LTD </option>
<option value="TH">A & B AUTOS </option>
<option value="NS">A & B BUCHAN </option>
<option value="LW">A & B CANDY STORE </option>
</select>
If for example I pick A STURROCK, the dropdown automatically changes to A COWAN. I have noticed this is because these two items have the same value - "ES".
Whenever an item is selected where there are two items with the same value the first item is selected.
Why does .net base its selected index on the value and not the item position. Is it possible to change this?
-
May 4th, 2005, 06:22 AM
#2
Frenzied Member
Re: Viewstate and autopostback
Reason being when the HTML is generated the selected index is not known client-side. Therefore when the HTML select is submitted ASP.NET is working with the information available.
If you submitted the form as HTML (not ASP.NET generated) you would only have access to the Request object and therefore only the values you have populated - no indexes!
Only suggestion I can make is change the values in the dropdown to be integers and have a hashtable containing keys and values so you can quickly lookup the selected value.
HTH
DJ
If I have been helpful please rate my post. If I haven't tell me!
-
May 4th, 2005, 07:24 AM
#3
Thread Starter
Fanatic Member
Re: Viewstate and autopostback
cheers, in the end I added a number to the two digit code to make them all unique, then took the number away before i used the code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|