GridView's Paging feature not working!

Discussion in 'ASP .Net' started by Guest, Dec 21, 2005.

  1. Guest

    Guest Guest

    Hello,

    I have a GridView in my ASP.NET 2.0 application that performs the paging
    feature perfect when I have it bound to a data source.

    But now I have it bound to a dataset and the paging feature will not work.

    When I try to use paging I get this error:

    The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.

    I realize that the PageIndexChanging event was not handled. How do I handle
    this event if I am using a dataset as the data source of the gridview
    control?

    Additionally, I have to use the dataset as the data source because I do alot
    of filtering and other stuff.

    Thanks,

    J
     
    Guest, Dec 21, 2005
    #1
    1. Advertisements

  2. Guest

    bhawin13 Guest

    Hello,
    Check out is there function which contains GridView1_PageIndexChanging
    or something like that.

    If such funcation not exist then select your grid in designer go to
    property window click on event button. then double click on
    OnSortCommand value field. It will generate event for you.

    Regarding paging code in that event find article on 4GuysFromRolla.com
    or DataGridGirl.com.

    Correct me if I am wrong.
    bhawin13
     
    bhawin13, Dec 22, 2005
    #2
    1. Advertisements

  3. Hi J,

    When you manually bind DataSet to GridView, we'll need to manually handle
    the paging work (register the PageIndexChanging event handler and bind the
    new page data to Gridview...). In the aspx , we need to specify the
    PageIndexChanging event handler as below:

    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
    OnPageIndexChanging="GridView1_PageIndexChanging"
    PageSize="5">


    The page's code behind is something like:

    GetDataSource() function is just a test funciton I used to return a
    certain DataSet that contains some data.....
    ======================================

    public partial class GridViews_GridViewManualPaging : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    GridView1.DataSource = GetDataSource();
    GridView1.DataMember = "items";
    GridView1.DataBind();
    }
    }
    protected void GridView1_PageIndexChanging(object sender,
    GridViewPageEventArgs e)
    {
    Response.Write("<br>NewpageIndex: " + e.NewPageIndex);
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataSource = GetDataSource();
    GridView1.DataBind();
    }

    private DataSet GetDataSource()
    {
    DataSet ds = new DataSet();
    DataTable dt = new DataTable("items");
    dt.Columns.Add("id", typeof(long));
    dt.Columns.Add("name", typeof(string));

    for (int i = 0; i < 50; i++)
    {
    DataRow dr = dt.NewRow();
    dr[0] = i + 1;
    dr[1] = "Item" + dr[0];
    dt.Rows.Add(dr);
    }

    ds.Tables.Add(dt);

    return ds;
    }
    }
    =====================

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    --------------------
    | Reply-To: <>
    | From: <>
    | Subject: GridView's Paging feature not working!
    | Date: Wed, 21 Dec 2005 14:40:19 -0800
    | Lines: 23
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | Message-ID: <uz3jE#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: ip-206.159.118.137.hdiss.net 206.159.118.137
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet:366424
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Hello,
    |
    | I have a GridView in my ASP.NET 2.0 application that performs the paging
    | feature perfect when I have it bound to a data source.
    |
    | But now I have it bound to a dataset and the paging feature will not work.
    |
    | When I try to use paging I get this error:
    |
    | The GridView 'gvResults' fired event PageIndexChanging which wasn't
    handled.
    |
    | I realize that the PageIndexChanging event was not handled. How do I
    handle
    | this event if I am using a dataset as the data source of the gridview
    | control?
    |
    | Additionally, I have to use the dataset as the data source because I do
    alot
    | of filtering and other stuff.
    |
    | Thanks,
    |
    | J
    |
    |
    |
     
    Steven Cheng[MSFT], Dec 22, 2005
    #3
  4. Guest

    manju.cdtech

    Joined:
    May 12, 2007
    Messages:
    1
    Likes Received:
    0
    manju.cdtech, May 12, 2007
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Coleen

    Datagrid Paging not working

    Coleen, Dec 31, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    4,699
    Coleen
    Dec 31, 2003
  2. =?Utf-8?B?TWl0Y2g=?=

    GridView Sorting and paging Not working

    =?Utf-8?B?TWl0Y2g=?=, Jun 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,294
    =?Utf-8?B?TWl0Y2g=?=
    Jun 12, 2006
  3. Replies:
    0
    Views:
    568
  4. getziiiiiiiiiii

    PAGING not working in ASP DataGrid

    getziiiiiiiiiii, Mar 12, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    877
  5. Ronald S. Cook
    Replies:
    3
    Views:
    3,340
    Alexey Smirnov
    May 6, 2007
  6. J. Muenchbourg

    Paging not working in a datagrid

    J. Muenchbourg, May 27, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    4
    Views:
    332
    J. Muenchbourg
    May 29, 2004
  7. Anonieko Ramos

    Why is my Paging not working in my DataGrid?

    Anonieko Ramos, Jul 31, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    197
    Anonieko Ramos
    Jul 31, 2004
  8. Ryan Rueckl

    DataGris Paging not working (event not firing)

    Ryan Rueckl, Jun 22, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    8
    Views:
    380
    Ryan Rueckl
    Jun 24, 2005
Loading...