set default paging to 3

5 replies. Last post: March 22, 2011 11:24 PM by Yudi
Tags :
  • (None)
David HaoMember

I am working on Webgrid and it has 1000 rows.

I set the paging size = 100

I want to know, can I set the default paging page to 3,  which is display rows from 301-400 in stead of display rows from 1-100  every time?


Thanks!


David




Answers

Yudi Member

There is no native way to set the page to a specific page number on the server-side code, but you might want to try this workaround.

First, add an ASP.NET HiddenField control, let’s say HiddenField1, into the page. Set the value of HiddenField1 in the Page_Load server-side event as shown in the following snippet code.

protected void Page_Load(object sender, EventArgs e)
{
    HiddenField1.Value = "3";
}

Modify the “GotoPage3” JavaScript function into the following.

window.onload = function () {
    var WebGrid1 = ISGetObject("WebGrid1");
    var page = document.getElementById("HiddenField1").value;

    WebGrid1.GotoPage(page);

    return true;
}

The modified JavaScript function will be executed on window on load. It will get the value of the HiddenField1 control and navigate WebGrid to the specified page.

Hope this helps.

All Replies

Yudi Member

Please try to add following JavaScript function (in OnAfterInitialize client-side event of WebGrid or on window on load) in order to set the default page to page 3.

function GotoPage3() {
    var WebGrid1 = ISGetObject("WebGrid1");
            
    WebGrid1.GotoPage(3);

    return true;
}

The GotoPage3 function utilizes GotoPage(n) method, where n is integer as the number of targeted page. The method switches to specific page of the data in WebGrid.

Hope this helps.

David HaoMember

But can we do this on the server side code?


Thanks!

Yudi Member

There is no native way to set the page to a specific page number on the server-side code, but you might want to try this workaround.

First, add an ASP.NET HiddenField control, let’s say HiddenField1, into the page. Set the value of HiddenField1 in the Page_Load server-side event as shown in the following snippet code.

protected void Page_Load(object sender, EventArgs e)
{
    HiddenField1.Value = "3";
}

Modify the “GotoPage3” JavaScript function into the following.

window.onload = function () {
    var WebGrid1 = ISGetObject("WebGrid1");
    var page = document.getElementById("HiddenField1").value;

    WebGrid1.GotoPage(page);

    return true;
}

The modified JavaScript function will be executed on window on load. It will get the value of the HiddenField1 control and navigate WebGrid to the specified page.

Hope this helps.

David HaoMember

Thanks!


David

Yudi Member

Should you need further assistance or run into any technical problems regarding our controls, feel free to post it into our forum. We would be happy to assist you again.

All times are GMT -5. The time now is 7:26 AM.
Previous Next