This is a migrated thread and some comments may be shown as answers.

Reposition RadGrid at top of grid after rebind

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JGavilan
Top achievements
Rank 1
JGavilan asked on 10 Dec 2013, 04:02 PM
I have a RadGrid that displays the results of a query submitted by the user. If the user requeries I want the vertical scroll position to be at the top of the grid, not at the position of the previous query. How do I do this?

I have tried the following in the PreRender event all to no avail:

           RadGrid1.MasterTableView.CurrentPageIndex = 0;

and this..

          if (RadGrid1.MasterTableView.Items.Count > 0)
            {
                RadGrid1.MasterTableView.Items[0].Selected = true;
            }

Here are my property settings

        <telerik:RadGrid ID="RadGrid1" runat="server" AllowSorting="True" Width="100%"  
            Height="450px" ShowStatusBar="True"
            AutoGenerateColumns="False" CellSpacing="0" GridLines="None" 
            onprerender="RadGrid1_PreRender" 
            onitemdatabound="RadGrid1_ItemDataBound" 
            ondetailtabledatabind="RadGrid1_DetailTableDataBind" 
            onneeddatasource="RadGrid1_NeedDataSource" 
                OnItemCreated="RadGrid1_ItemCreated" 
                onsortcommand="RadGrid1_SortCommand">
                  <MasterTableView DataKeyNames="GloveId, MaterialType, Chemical" HierarchyDefaultExpanded="true" Name="PermDataGroup" CssClass="masterTablePadding" 
                GroupsDefaultExpanded="False" >


Thanks,
Rob

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 13 Dec 2013, 09:55 AM
Hello Rob,

One approach to bring the grid into view is to use the following:
protected void Button1_Click(object sender, EventArgs e)
{
    RadGrid1.Rebind();
    RadGrid1.Focus();
}

However, for scrolling the window to its top, you need a different client-side approach:
<asp:HiddenField ID="HiddenField1" runat="server" Value="false" />
C#:
protected void Button1_Click(object sender, EventArgs e)
{
    RadGrid1.Rebind();
    HiddenField1.Value = "true";
}
JavaScript:
function pageLoad() {
    var field = $get('<%= HiddenField1.ClientID %>');
    if (field.value == "true") {
        field.value = "false";
        $(document).scrollTop($('<%= "#"+RadGrid1.ClientID %>').offset().top);
    }
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
JGavilan
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or