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

Scroll to Item

1 Answer 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reiner Ebel
Top achievements
Rank 1
Reiner Ebel asked on 22 Oct 2010, 06:14 PM
Hello,
i use a RadGrid in a UpdatePanel. The cells contain ImageButtons.

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>        
            <telerik:RadGrid ID="RadGrid1" runat="server" Width="900px" Height="400px" 
                Skin="Office2007"  
                onitemdatabound="RadGrid1_ItemDataBound" 
                onitemcommand="RadGrid1_ItemCommand" GridLines="None" >
                <ClientSettings>
                    <Scrolling AllowScroll="true" UseStaticHeaders="true"   FrozenColumnsCount="1" SaveScrollPosition="true"/> 
                </ClientSettings
                <MasterTableView TableLayout="Auto" />
                <HeaderStyle Width="100px" />                              
            </telerik:RadGrid>        
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="RadGrid1" EventName="ItemCommand" />
        </Triggers>
</asp:UpdatePanel>

Code:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
          
        GridDataItem item = (GridDataItem)e.Item;
  
        Label lbl = new Label();
        lbl.Text = item[""].Text.Substring(item[""].Text.IndexOf("|") + 1);
        item[""].Controls.Add(lbl);
  
        for (int i = 0; i < gruppenliste.Count; i++)
        {
            ImageButton imgbtn = new ImageButton();
  
            if (item[gruppenliste[i].ToString()].Text.StartsWith("0"))
            {
                imgbtn.CommandName = "add";
                imgbtn.ImageUrl = "../img/cancel.gif";
                item[gruppenliste[i].ToString()].Controls.Add(imgbtn);
                item[gruppenliste[i].ToString()].HorizontalAlign = HorizontalAlign.Center;
                imgbtn.CommandArgument = item[""].Text.Substring(
                    0, item[""].Text.IndexOf("|")) +
                    "|" +
                    item[gruppenliste[i].ToString()].Text.Substring(
                    item[gruppenliste[i].ToString()].Text.IndexOf("|") + 1);
            }
            else
            {
  
                imgbtn.CommandName = "del";
                imgbtn.ImageUrl = "../img/ok.gif";
                item[gruppenliste[i].ToString()].Controls.Add(imgbtn);
                item[gruppenliste[i].ToString()].HorizontalAlign = HorizontalAlign.Center;
                imgbtn.CommandArgument = item[""].Text.Substring(
                    0, item[""].Text.IndexOf("|")) +
                    "|" +
                    item[gruppenliste[i].ToString()].Text.Substring(
                    item[gruppenliste[i].ToString()].Text.IndexOf("|") + 1);
            }
        }
    }
}

When I click a ImageButton, then the grid in the UpdatePanel is refreshed.
How can I automatically scroll back to the current row/column (ImageButton) after the refresh?

Reiner

1 Answer, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 27 Oct 2010, 09:20 AM
Hello Reiner,

Your RadGrid definition seems OK. Setting SaveScrollPosition="true" successfully saves the grid scroll position on AJAX and you get the position persisted on AJAX requests. Attaching a test page to demonstrate.

Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Reiner Ebel
Top achievements
Rank 1
Answers by
Veli
Telerik team
Share this question
or