reset selected index on droplist

T

TJS

After a post back the selected index should be rest in a droplist to match
user's choice, but page always show selected item as first one in the
droplist.

How can iforce the selected item to be reset

I have:

Sub Page_Load(s As Object, e As EventArgs)
If Page.IsPostBack then
If len( request.params("idx")) then vSelectedItem =
request.params("idx")
SearchList.SelectedIndex= vSelectedItem
End if
end sub


Sub ApplyFilter_Click(s As Object, e As EventArgs)
Dim vSelectedItem As String
vSelectedItem = SearchList.SelectedIndex
response.redirect("Editor.aspx?idx=" & vSelectedItem)
End Sub
 
T

TJS

if I manually hard code a value into the selectedindex, then the droplist
reselects correctly . But the problem appears to be the index of the user
selection is always returned as zero in ApplyFilter_Click. any idea why ?

Sub ApplyFilter_Click(s As Object, e As EventArgs)
Dim vSelectedItem As String
vSelectedItem = SearchList.SelectedIndex
response.redirect("Editor.aspx?idx=" & vSelectedItem)
End Sub

........
<asp:DropDownList
id="SearchList"
AutoPostBack="False"
runat="server" cssClass="">
</asp:DropDownList>

<asp:Button id="SearchButton"
onclick="ApplyFilter_Click"
runat="server"
Text="GO">
</asp:Button>


================sample html output ================
<select name="SearchList" id="SearchList">
<option value="59">test1 </option>
<option value="60">test2 </option>
<option value="61">test3 </option>
</select>
 
M

MasterGaurav

So, you get SearchList.SelectedIndex = 0 always?

What all other event-handlers do you have for the page? The situtation
is highly unlikely.

What version of ASP.Net (with SP) are you using? If you've applied SP
1, try reinstalling the javascript files. You can do this by:

%WINDIR%\Microsoft.Net\Framework\v1.1.4322\aspnet_regiis -c


--
Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://mastergaurav.blogspot.com
----------------------
 
T

TJS

I changed my code to be

ID = Int32.Parse(SearchList.SelectedItem.Value)

and now it works
 

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,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top