Paging DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am having a problem finding out how to page a datagrid.

I have the procedure for moving from page to page as:

private void changePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgCustInfo.CurrentPageIndex = e.NewPageIndex;
--connection information and SELECT statement here not in a separate
procedure--

I have an Edit button in the datagrid to edit the record, but when I click
on it I get an error saying that the pageindex must be >0 <pagecount.

In the editRecord procedure I have the connection information and SELECT
statement to display only the record being edited in the datagrid and
textboxes outside the datagrid that display the data to be edited.

Can someone help me out?

Thanks,


Antonio
 
When you edit the PageIndex property goes to -1. you can validate that in
the changePage method to don't do paging like:
if(e.NewPageIndex != -1)
{
}

Regards,

Bela Istok
 
Hi. Thanks for replying. Here is the full procedure I have, so, maybe it can
give more details and help:

private void changePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgCustInfo.CurrentPageIndex = e.NewPageIndex;

SqlConnection conn = new SqlConnection
(ConfigurationSettings.AppSettings["SqlConnectionString"]);

conn.Open();

SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = conn;
dataCommand.CommandText = "SELECT GEM.customers.name AS [Institution
Name], "
+ "GEM.customers.CustomerSince AS [Customer Since], "
+ "GEM.contacts.name_first AS [First Name], "
+ "GEM.contacts.name_last AS [Last Name], "
+ "GEM.contacts.title AS [Contact Title], "
+ "GEM.customers.address_1 AS Address, "
+ "GEM.customers.city AS City, "
+ "GEM.customers.state AS State, "
+ "GEM.customers.province AS Province, "
+ "GEM.customers.zip_code AS [Zip Code], "
+ "GEM.customers.postal_code AS [Postal Code], "
+ "GEM.customers.country AS Country, "
+ "GEM.customers.phone AS Phone, "
+ "GEM.contacts.email AS [E-Mail Address], "
+ "GEM.customers.cust_id "
+ "FROM GEM.customers INNER JOIN GEM.config_usernames ON "
+ "GEM.customers.cust_id = GEM.config_usernames.cust_id INNER JOIN "
+ "GEM.contacts ON GEM.config_usernames.contact_id =
GEM.contacts.contact_id ORDER BY GEM.customers.name";

SqlDataAdapter adapter = new SqlDataAdapter(dataCommand);
DataSet ds = new DataSet();
adapter.Fill(ds);
dgCustInfo.DataSource = ds;
dgCustInfo.DataBind();
conn.Close();
}
 
Back
Top