How to Current Selected page of RadGrid

7 posts, 0 answers
  1. CHETAN JAITLY
    CHETAN JAITLY avatar
    16 posts
    Member since:
    Jan 2009

    Posted 17 Feb 2009 Link to this post

    Hi
    I have RadGrid Control on the page which consist more then 100 pages.
    I have to highlight current selected page so that business user can have track of current page .

    Can you suggest for the same.


    Thanks
    Shrirang
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Feb 2009 Link to this post

    Hi Chethan,

    Here is the code snippet to highlight the current page number in the Grid pager. Give a try with the following code and see if it meets your requirement.

    ASPX:
     
    <MasterTableView AutoGenerateColumns="false" AllowPaging="true" PageSize="5"
     
    PagerStyle-Mode="NextPrevNumericAndAdvanced"   > 
                 

    CS:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
     
            if (e.Item is GridPagerItem) 
            { 
                GridPagerItem pager = (GridPagerItem)e.Item; 
               
                Panel pagerPanel = (Panel)pager.PagerContentCell.FindControl("ctl00"); 
                for (int i = 0; i <= pagerPanel.Controls.Count; i++) 
                { 
                    string strCurrentPage = Convert.ToString(RadGrid1.CurrentPageIndex + 1); 
                    if (pagerPanel.Controls[i].ToString()== "System.Web.UI.WebControls.Label"
                    { 
                        Label lblPage = (Label)pagerPanel.Controls[i]; 
                        if (lblPage.Text == strCurrentPage) 
                        { 
                            lblPage.BackColor = System.Drawing.Color.Red; 
                            break
                        } 
                    } 
                } 
            } 
       } 


    Regards
    Shinu
  3. Waseem
    Waseem avatar
    85 posts
    Member since:
    Jun 2012

    Posted 08 Nov 2013 Link to this post

    Hi

    In RadGrid, when i click on pageIndex 4 first time . it show CurrentpagesIndex 0.

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    int CurrentPageIndex = 0;
                    if (Session["EmployerCurrentPageIndex"] != null)
                    {
                        int.TryParse(Convert.ToString(Session["EmployerCurrentPageIndex"]), out CurrentPageIndex);
                    }
                    EmployerLinkGrid1.CurrentPageIndex = CurrentPageIndex;

                    BindGrid();
                }
            }


     string strCurrentPageIndex = EmployerLinkGrid1.MasterTableView.CurrentPageIndex.ToString();

    protected void EmployerLinkGrid1_ItemCommand(object sender, GridCommandEventArgs e)
     {
        Session["EmployerCurrentPageIndex"] = EmployerLinkGrid1.CurrentPageIndex;
    }

    I check it many way, when click on PagesIndex 4 , it should not show 0. everytime it show previous value.
    When click on pageIndex 4, it show 0
    then click on pageIndex 1, it show 3
    Its really confusing.

    Thanks,
    Muhammad Waseem
    the Telerik Team
  4. Waseem
    Waseem avatar
    85 posts
    Member since:
    Jun 2012

    Posted 08 Nov 2013 Link to this post

    My goodness, i achieve my desired result by using OnPageIndexChanged.

    OnPageIndexChanged="EmployerLinkGrid1_PageIndexChanged"


            protected void EmployerLinkGrid1_PageIndexChanged(object sender, Telerik.Web.UI.GridPageChangedEventArgs e)
            {
                string str = e.NewPageIndex.ToString();
            } 

    Thanks,
    Muhammad Waseem
    the Telerik team


  5. Rolland
    Rolland avatar
    6 posts
    Member since:
    Sep 2016

    Posted 17 Oct 2016 in reply to Waseem Link to this post

    Sweet exactly what I was searching for,

    Works like a charm.

    Thanks 

  6. sergio
    sergio avatar
    2 posts
    Member since:
    Feb 2020

    Posted 27 Feb Link to this post

    We have to do all this just to get a simple page number ? It´s better program my own UI. 
  7. Rumen
    Admin
    Rumen avatar
    14284 posts

    Posted 09 Apr Link to this post

    Hi Sergio,

    Thank you for the valuable feedback we received from you via email and here at the Telerik forums! It is much appreciated!

    If the Telerik UI for ASP.NET AJAX suite does not match your requirements for solely C# development, you might be interested in to check our other offerings which are entirely C# based:

    If you have any questions, please open a support ticket or open a new forum thread and we will be glad to provide the needed information and to assist you.

    Regards,
    Rumen
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top