tomhartland
04-22-2004, 05:29 AM
Greetings :-)
I'm having trouble getting the paging to work on one of my DataGrid web controls. The following C# code lives behind a simple ASPX page containing a single PlaceHolder control...private void Page_Load(object sender, System.EventArgs e)
{
// Create a table, column and 25 rows
DataTable obDataTable = new DataTable( "testtable" );
obDataTable.Columns.Add( new DataColumn( "testcol1" ) );
for ( int iLoop=0; iLoop<25; iLoop++ )
obDataTable.Rows.Add( new object[] { "a" + iLoop.ToString() } );
// Create datagrid and set the paging to 10
DataGrid obDataGrid = new DataGrid();
obDataGrid.AllowPaging = true;
obDataGrid.PageSize = 10;
obDataGrid.PageIndexChanged += new
DataGridPageChangedEventHandler( PageChanged );
// Set the Data source, bind and add to the placeholder
obDataGrid.DataSource = obDataTable.DefaultView;
obDataGrid.DataBind();
PlaceHolder1.Controls.Add( obDataGrid );
}
protected void PageChanged( object objSender,
DataGridPageChangedEventArgs eArgs )
{
// Cast the datagrid and set the page index
DataGrid obDataGrid = (DataGrid)objSender;
obDataGrid.CurrentPageIndex = eArgs.NewPageIndex;
obDataGrid.DataBind();
}Moving forward through the pages works correctly, and I can breakpoint in the PageChanged handler. However the Previous button does not fire the event handler (but does fire Page_Load) and the data on screen becomes corrupt.
Using the above code, the 3 pages show correctly, but clicking Previous on the 3rd page (which has the last 5 entries) produces a page showing the same 5 entries, plus the last 5 entries from the 1st page.
This can be also be reproduced with the PagerStyle.Mode set to Numbered.
Does anybody have any ideas? Why is the event handler not being called for the Previous button? Any help would be greatly appreciated.
Cheers,
Tom
I'm having trouble getting the paging to work on one of my DataGrid web controls. The following C# code lives behind a simple ASPX page containing a single PlaceHolder control...private void Page_Load(object sender, System.EventArgs e)
{
// Create a table, column and 25 rows
DataTable obDataTable = new DataTable( "testtable" );
obDataTable.Columns.Add( new DataColumn( "testcol1" ) );
for ( int iLoop=0; iLoop<25; iLoop++ )
obDataTable.Rows.Add( new object[] { "a" + iLoop.ToString() } );
// Create datagrid and set the paging to 10
DataGrid obDataGrid = new DataGrid();
obDataGrid.AllowPaging = true;
obDataGrid.PageSize = 10;
obDataGrid.PageIndexChanged += new
DataGridPageChangedEventHandler( PageChanged );
// Set the Data source, bind and add to the placeholder
obDataGrid.DataSource = obDataTable.DefaultView;
obDataGrid.DataBind();
PlaceHolder1.Controls.Add( obDataGrid );
}
protected void PageChanged( object objSender,
DataGridPageChangedEventArgs eArgs )
{
// Cast the datagrid and set the page index
DataGrid obDataGrid = (DataGrid)objSender;
obDataGrid.CurrentPageIndex = eArgs.NewPageIndex;
obDataGrid.DataBind();
}Moving forward through the pages works correctly, and I can breakpoint in the PageChanged handler. However the Previous button does not fire the event handler (but does fire Page_Load) and the data on screen becomes corrupt.
Using the above code, the 3 pages show correctly, but clicking Previous on the 3rd page (which has the last 5 entries) produces a page showing the same 5 entries, plus the last 5 entries from the 1st page.
This can be also be reproduced with the PagerStyle.Mode set to Numbered.
Does anybody have any ideas? Why is the event handler not being called for the Previous button? Any help would be greatly appreciated.
Cheers,
Tom