AxleWack AxleWack - 4 months ago 19
Vb.net Question

Getting ScrollHeight of RadGrid

How do I get the scrollheight of a RadGrid ?

So if I scroll down and click edit on a row, I want to save that scroll position so that when I scroll down to click on update, it will take me back to the scroll position when I clicked edit.

I have tried :

HiddenField.Value= rGVDELTaskLog.ClientSettings.Scrolling.ScrollHeight.ToString()


This returns the full height of the grid(400px in this case)

I have tried:
HiddenField.Value = rGVDELTaskLog.ClientSettings.Scrolling.ScrollTop


This returns 0 when scrolling right to the top, but when scrolling right to the bottom it returns 183px and not 400px.

How do I get the ScrollHeight that the scroll bar is on when I click edit ?

Answer

I found the solution myself.

On the EditCommand of the RadGrid, I retrieved the value for ScrollTop and saved it into a HiddenField. This way the scroll position will be set to the exact scroll position it was on when you clicked edit :

 Protected Sub rGVDELTaskLog_EditCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles rGVDELTaskLog.EditCommand
    Dim ScrollPosition As Integer

    If TypeOf e.Item Is GridDataItem Then
        If rGVDELTaskLog.ClientSettings.Scrolling.ScrollTop = "" Then
            ScrollPosition = 0
        Else
            ScrollPosition = rGVDELTaskLog.ClientSettings.Scrolling.ScrollTop
        End If

        hidScrollPosition.Value = ScrollPosition

    End If
End Sub

I then Set the ScrollTop of the RadGrid to the value in the HiddenField on say for example on the CancelCommand(The same would go for the UpdateCommand) :

Protected Sub rGVDELTaskLog_CancelCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles rGVDELTaskLog.CancelCommand
    rGVDELTaskLog.ClientSettings.Scrolling.ScrollTop = hidScrollPosition.Value
End Sub