473,473 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with datagrid paging in C#

I can't get my datagrid to page correctly and I think it's just the
order of events that's confusing me. What's happening as it stands
now is, I hit the Search button, which fires the btnSearch_Click
method, which sets stored procedure parameters and executes the stored
procedure then rebinds the datagrid. Everything's fine so far, but
when I click a page # at the bottom of the datagrid, it goes to page
2, but page 2 of the entire dataset, not of the dataset rebound after
btnSearch_Click fired.

here's the relevant code:

using ...

namespace Mappy
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConnection;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand2;
protected System.Data.SqlClient.SqlDataReader sqlDataReader1;
protected System.String strSQL;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox txtProjMapName;
protected System.Web.UI.WebControls.Label lblProjMapName;
protected System.Web.UI.WebControls.Label lblRoadName;
protected System.Web.UI.WebControls.TextBox txtRoadName;
protected Mappy.DataSet1 dataSet11;
...
private void Page_Load(object sender, System.EventArgs e)

{

sqlConnection.Open();
if (!Page.IsPostBack)
{
ViewState.Add("AdvancedSearchFieldsVisible", false);

//Populate Dropdowns
System.Data.SqlClient.SqlCommand sqlCommand2 = new
System.Data.SqlClient.SqlCommand("Select * from tblMapType order by
MapType ASC",sqlConnection);

//Map Type
sqlCommand2.CommandType = CommandType.Text;
sqlCommand2.Connection = sqlConnection;
sqlDataReader1 =
sqlCommand2.ExecuteReader(System.Data.CommandBehav ior.SequentialAccess);
ddlMapType.DataBind();
sqlDataReader1.Close();

//add an empty list item for when you want to search by map type =
""
ddlMapType.Items.Add(new ListItem("", ""));
ddlMapType.Items[ddlMapType.Items.Count - 1].Selected = true;
}

}


private void btnSearch_Click(object sender, System.EventArgs e)
{
//Assign values to stored procedure parameters
//RoadName
sqlDataAdapter1.SelectCommand.Parameters[1].Value =
txtRoadName.Text.ToString();
//ProjMapName
sqlDataAdapter1.SelectCommand.Parameters[2].Value =
txtProjMapName.Text.ToString();
...
BindData();

}
protected void BindData()
{
// dataSet11.Clear();
sqlDataAdapter1.Fill(dataSet11);
// dataSet11.AcceptChanges();
DataGrid1.DataSource = dataSet11.Tables[0].DefaultView;
DataGrid1.CurrentPageIndex = 0;
DataGrid1.DataBind();

}


protected void ChangeGridPage(object sender,
DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
try{
sqlDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}
catch (Exception ex)
{
string message;
message = ex.Message;
Label1.Text = message + "<BR><BR>" + e.NewPageIndex;

}

}


}
}
Nov 18 '05 #1
1 1193


What you may want to do is change this so that
ChangeGridPage calls your BindData routine (obviously this means
changing a few lines in the functions).

If you look at the Page Source link here it may provide you with a good
model:

http://www.asp.net/ReportsStarterKit...aspx?path=simp
le.src&file=simple&rows=5

Jim

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

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...
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...
5
by: quanga | last post by:
Hi- I have a datagrid that in some cases can be several thousand rows in length. What I'd like it to do is have the data pushed to the browser after every, say, 100 rows or so. Kind of a...
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...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
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...
0
by: richard | last post by:
OK, Im finished pulling my hair out and now I need help. I have created a VB class file for my custom paging, in it I create a table with 2 rows, in the rows I have linkbuttons for first page,...
1
by: ABHIJIT B | last post by:
Hi, I am using 2 web pages parent and popup.PopUp window is opened using window.showModalDialog().This is client requiremnt they don't wnat window.open() In PopUp page I am using GridView and...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.