Paging of a data grid

  • Thread starter Thread starter Andrew Banks
  • Start date Start date
A

Andrew Banks

I've added a data grid to my page but the automatic paging feature doesn't
seem to be working.

The code I have on page load is as follows. Can anyone suggest why this
isn't working?

SqlDataAdapter adSales;
SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("Co
nnectionString"));
adSales = new SqlDataAdapter("SELECT * FROM AllOrdersOverview ORDER BY
OrderDate ASC", con);
DataSet dsSales = new DataSet();
adSales.Fill(dsSales,"Sales");
grdSales.DataSource = dsSales;
grdSales.DataBind();
Page.DataBind();
 
Hi, Andrew

What do you get? An error or an unpaged data grid?

Bin Song, MCP

----- Andrew Banks wrote: -----

I've added a data grid to my page but the automatic paging feature doesn't
seem to be working.

The code I have on page load is as follows. Can anyone suggest why this
isn't working?

SqlDataAdapter adSales;
SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("Co
nnectionString"));
adSales = new SqlDataAdapter("SELECT * FROM AllOrdersOverview ORDER BY
OrderDate ASC", con);
DataSet dsSales = new DataSet();
adSales.Fill(dsSales,"Sales");
grdSales.DataSource = dsSales;
grdSales.DataBind();
Page.DataBind();
 
like bill said:

Private Sub dataGrid2_PageIndexChanged(ByVal source As System.Object, ByVal
e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles
DataGrid2.PageIndexChanged

DataGrid2.CurrentPageIndex = e.NewPageIndex
getData()

End Sub

*** When you do this, your program will throw an error when you delete the
last item on a datagrid page. Therefore when you load your datagrid
you must have the following: ***

Try 'need this try/catch when datagrid allows paging and the last item of a
"page" is deleted
DataGrid2.DataBind()
Catch
DataGrid2.CurrentPageIndex = DataGrid2.PageCount - 1
DataGrid2.DataBind()
End Try
 
Back
Top