473,379 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Paging DataGrid

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.DataGridPageChangedEvent Args 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

Jun 28 '06 #1
3 2224
The correct event should be PageIndexChanging in Gridview but
PageIndexChanged in DataGrid:
http://msdn2.microsoft.com/en-us/lib...xchanging.aspx
http://msdn2.microsoft.com/en-us/lib...ed(d=ide).aspx

chanmm

"Antonio" <An*****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
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.DataGridPageChangedEvent Args 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

Jun 28 '06 #2
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

"Antonio" <An*****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
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.DataGridPageChangedEvent Args 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


Jun 28 '06 #3
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.DataGridPageChangedEvent Args 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();
}
"chanmm" wrote:
The correct event should be PageIndexChanging in Gridview but
PageIndexChanged in DataGrid:
http://msdn2.microsoft.com/en-us/lib...xchanging.aspx
http://msdn2.microsoft.com/en-us/lib...ed(d=ide).aspx

chanmm

"Antonio" <An*****@discussions.microsoft.com> wrote in message
news:72**********************************@microsof t.com...
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.DataGridPageChangedEvent Args 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


Jun 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RelaxoRy | last post by:
sqlConnection1.Open(); myReader = sqlCommand1.ExecuteReader(); DataGrid1.DataSource = myReader; DataGrid1.DataBind(); myReader.Close(); sqlConnection1.Close(); The Datagrid populates fine. ...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
2
by: RJN | last post by:
Hi Sorry for posting again. I have a datagrid which is put inside a div tag to make it scrollable. I need to page the datagrid. The page numbers appear at the bottom of the datagrid and has...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
2
by: asad | last post by:
Hello friends, i am designing a ASP.NET page where i want to use custom paging bcoz data is too heavy so pls tell me how can i use custom paging in ASP.NET Thanks
2
by: Axel Dahmen | last post by:
Hi, I'm using a DataGrid control to show a table's content with paging. For navigation through the pages I'm using the DataGrid's intrinsic navigation section. My problem: The DataGrid...
0
by: Pat | last post by:
I have 3 Datagrid nested. Master Details Child The master has paging (And i'm using the paging inbuilt in the Datagrid) in the Master DataGrid you select a linkbutton(using commandname) and it...
3
by: Pat | last post by:
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i populate the Child databrid using myDataGrid.SelectedIndex value as the filter and setting the DataKeyField. I enabled...
2
by: rn5a | last post by:
In a shopping cart app, a ASPX page retrieves the order details & personal details of a user from a MS-Access database table depending upon the username of the user. The order details of a...
5
by: Donald Adams | last post by:
Hi, I will have both web and win clients and would like to page my data. I could not find out how the datagrid control does it's paging though I did find some sample code that says they do it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.