GridView's Paging feature not working!

G

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
 
B

bhawin13

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
 
S

Steven Cheng[MSFT]

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: <[email protected]>
| From: <[email protected]>
| 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#[email protected]>
| 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
|
|
|
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top