By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,626 Members | 2,202 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,626 IT Pros & Developers. It's quick & easy.

GridView's Paging feature not working!

P: n/a
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
Dec 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Dec 22 '05 #2

P: n/a
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: <wa********@newsgroups.nospam>
| From: <wa********@newsgroups.nospam>
| 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: <uz**************@TK2MSFTNGP09.phx.gbl>
| 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!TK2MSFT NGP09.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
|
|
|

Dec 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.