views:

31

answers:

1

I've got an ASP.NET (VB) page with two listboxes. Standard stuff - select an item on left, hit add button and it moves to right, etc. I've also got two buttons to move items up or down in the resulting list. My problem is that if I go to the 2nd to the last item (or any in that range) and move it down in the list the list resets the scrollbar to the top position. I want the focus to be on the item that was promoted or demoted, regardless of whether it is "beneath the fold" or not.

I've got MaintainScrollPositionOnPostBack in my page declaration and it works great for the page as a whole, and although it does nothing for the listbox, this is the type of behavior I'm looking for. Can this be done in just VB, without resorting to Javascript or AJAX?

Thanks in advance for any ideas or suggestions you may have. Code snippet below:

If lstToFields.SelectedIndex < lstToFields.Items.Count - 1 Then
    Dim RowNum As Integer = lstToFields.SelectedIndex
    Dim RowVal As ListItem = lstToFields.SelectedItem
    lstToFields.Items.RemoveAt(RowNum)
    lstToFields.Items.Insert(RowNum + 1, RowVal)
    lstToFields.SelectedIndex = RowNum + 1
End If
A: 
Blanthor
I got the hint for this solution from this posting: http://stackoverflow.com/questions/543131/maintain-scroll-position-in-listboxes-in-updatepanels-not-the-page
Blanthor