reset selected index on droplist

  • Thread starter Thread starter TJS
  • Start date Start date
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
 
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>
 
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
----------------------
 
I changed my code to be

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

and now it works
 
Back
Top