locked
Paging Issue if webgrid no of rows is dynamic RRS feed

  • Question

  • User-1327394822 posted

    In a webgrid, I am setting the rowsPerPage parameter to a value that I fetch from the form via a select box

    var pagingnNumber = !Request["paging"].IsEmpty() ? Request["paging"] : "3";
        var grid = new WebGrid(source : data, 
                               rowsPerPage: pagingnNumber.AsInt(),
                               defaultSort: "ProductId", 
                               fieldNamePrefix: "grid1"
                               );

    Page 1 is good, but page 2 rowsPerPage is set back to the false condition (3) of the if statement.

    1) the issue is with the a links in tfoot. Is there a solution to this?

    2) Is it ok to put the selectlist value in cache or session variable? Is it considered good programming practice?

    Friday, December 4, 2015 8:44 PM

Answers

  • User325035487 posted

    Where are you getting value of Request["paging"] from ? If its a post data from a form it wont be available for page 2.. You can send it as a QueryString value by changing form method="get"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 5, 2015 9:34 AM

All replies

  • User-1327394822 posted

    Built a cookie solution... Can anyone suggest without the use of cookie... & is it better to store in session variable or cookie..

    var viewPerPage = "3";
        if(Request.Cookies["viewsPerPageCookie"] != null){
            viewPerPage = Request.Cookies["viewsPerPageCookie"].Value;
        }
        if(IsPost){
            viewPerPage = Request["paging"];
            Response.Cookies["viewsPerPageCookie"].Value = viewPerPage;
            Response.Cookies["viewsPerPageCookie"].Expires = DateTime.Now.AddDays(7);
        }
    
        var grid = new WebGrid(source : data, 
                               rowsPerPage: viewPerPage.AsInt(),
                               defaultSort: "ProductId", 
                               fieldNamePrefix: "grid1"
                               );

    Saturday, December 5, 2015 9:32 AM
  • User325035487 posted

    Where are you getting value of Request["paging"] from ? If its a post data from a form it wont be available for page 2.. You can send it as a QueryString value by changing form method="get"

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 5, 2015 9:34 AM