Sunday, February 04, 2007

GridView's Paging feature not working!

GridView's Paging feature not working!



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:



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(" " + 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.)

--------------------



| 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

|

|





powered by performancing firefox

No comments: