Panel scroll position reset on postback


G

Guest

I have added Panel control to a web page which contains a GridView. The
Panel's ScrollBars property is set to auto. When I select the Select
CommanField button for a row (which obviously causes a postback), the scroll
position resets to the top.

I was unable to figure out how to not force a postback or how to reset the
scroll position of the GridView.

What are my options here?

Thanks,
Ryan
 
Ad

Advertisements

G

Guest

I have tried that and it doesn't work. I am not sure if that setting applies
to a scroll within a panel.
 
Ad

Advertisements

C

Chris Botha

This can be done, but is not too straight forward, you need to know which
row was clicked and then a bit of Java script as well.

In the Code Behind, declare a variable to hold the row ID, something like:
Protected m_SelectedRowId As String = ""

After you did the DataBind() on the grid, each row must get an ID:
DataGrid1.DataBind()
Dim oneItem As DataGridItem, rowCtr As Integer
For Each oneItem In DataGrid1.Items
oneItem.ID = "Row_" & rowCtr
rowCtr += 1
Next

In the Code Behind you need the ID of the row clicked, use the ItemCommand
handler:
Private Sub DataGrid1_ItemCommand(yada yada ...)
m_SelectedRowId = e.Item.ClientID
.....
End Sub

Now in the Java Script the row must be scrolled into view.
Go into HTML design view of the form and paste this right at the bottom of
the page, below everything else
<script language=javascript>
<!--
var theRowId = '<%=m_SelectedRowId%>';
if (theRowId != "") {
document.getElementById(theRowId).scrollIntoView();
}
//-->
</script>

I've copied and pasted everything from one of my pages where it is used,
should work.
 

Top