Paging of a data grid

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();
 
G

Guest

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();
 
R

Reva Baum

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
 

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,012
Latest member
RoxanneDzm

Latest Threads

Top