locked
Way to programmatically change Grid Page Numbers/Names? RRS feed

  • Question

  • Is there any way to programmatically set/change the Grid Page Numbers/Names?

    i.e. Instead of Pages 1 to 5, I'd like it to display January to May.  Is there a way?

    Thank you.

    Thursday, February 14, 2013 1:11 PM

Answers

  • Hello

    You cannot do this with the standard grids (AFIK) but you can create your own paging system and then label that accordingly. What you would need to do is create a custom datagrid which there are plenty of code samples about for and then when it comes to the paging you create the buttons and text as you wish to show them. I have four buttons called FirstPage, LastPage, NextPage and PreviousPage along with a textbox called Page and a label called PageNumber and here is the code

    	partial void FirstPage_Execute()
            {
                this.YourDataSet.Details.PageNumber = 1;
                this.PageNumber = " of " + this.YourDataSet.Details.PageCount.ToString();
                this.Page = this.YourDataSet.Details.PageNumber.ToString();
            }
            partial void Lastpage_Execute()
            {
                this.YourDataSet.Details.PageNumber = this.YourDataSet.Details.PageCount;
                this.PageNumber = " of " + this.YourDataSet.Details.PageCount.ToString();
                this.Page = this.YourDataSet.Details.PageNumber.ToString();
            }
    
            partial void NextPage_Execute()
            {
                // Write your code here.
                this.YourDataSet.Details.PageNumber += 1;
                this.PageNumber = " of " + this.YourDataSet.Details.PageCount.ToString();
                this.Page = this.YourDataSet.Details.PageNumber.ToString();
            }
    
            partial void NextPage_CanExecute(ref bool result)
            {
                // Write your code here.
                result = this.YourDataSet.Details.PageNumber < this.YourDataSet.Details.PageCount;
            }
    
            partial void PreviousPage_Execute()
            {
                // Write your code here.
                this.YourDataSet.Details.PageNumber -= 1;
                this.PageNumber = " of " + this.YourDataSet.Details.PageCount.ToString();
                this.Page = this.YourDataSet.Details.PageNumber.ToString();
            }
            partial void PreviousPage_CanExecute(ref bool result)
            {
                // Write your code here.
                result = this.YourDataSet.Details.PageNumber > 1;
            }
    
            partial void EditableGrid_Created()
            {
                // Write your code here.
                this.Page = "1";
                if (this.YourDataSet.Details.PageCount < 1)
                {
                    this.PageNumber = " of 1*";
                }
                else
                {
                    this.PageNumber = " of " + this.YourDataSet.Details.PageCount.ToString();
                }

    You would, of course, replace YourDataSet with your own dataset name and instead of doing the numbers you could use a function to convert that to the month name maybe or just an array with months in?

    If you found this post helpful, please mark it as helpful. If by some chance I answered the question, please mark the question as answered. That way you will help more people like me :)

    • Proposed as answer by Yann DuranModerator Thursday, February 14, 2013 2:24 PM
    • Marked as answer by Angie Xu Tuesday, February 26, 2013 5:19 AM
    Thursday, February 14, 2013 2:20 PM