473,398 Members | 2,165 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,398 software developers and data experts.

Paging in Gridview with datatable

112 100+
Hello

Can somebody please help me with the paging in a grid-view.
please find my code below

Expand|Select|Wrap|Line Numbers
  1. SqlDataAdapter sda = new SqlDataAdapter();
  2.         DataTable dt = new DataTable();
  3.         protected void search_Click(object sender, EventArgs e)
  4.         {
  5.             string connstring = System.Configuration.ConfigurationManager.ConnectionStrings["xxxxxxxxxx"].ConnectionString;
  6.             SqlConnection conn = new SqlConnection(connstring);
  7.             SqlCommand cmd = new SqlCommand("sp_xxxxxx_New");
  8.             cmd.CommandType = CommandType.StoredProcedure;
  9.             cmd.Connection = conn;
  10.             cmd.Parameters.AddWithValue("@city", city.Text);
  11.             cmd.Parameters.AddWithValue("@state_abbrev", state.SelectedValue);
  12.             sda.SelectCommand = cmd;
  13.             sda.Fill(dt);
  14.             GridView.DataSource = dt;
  15.             GridView.DataBind();
  16.  
  17.         }
  18.         protected void GridView_PageIndexChanging(Object sender, GridViewPageEventArgs e)
  19.         {
  20.  
  21.             GridView.PageIndex = e.NewPageIndex;
  22.             //sda.Fill(dt);
  23.             GridView.DataSource = dt;
  24.             GridView.DataBind();
  25.         }
i understand that I am missing something very important here..but do not know what it is.
I get the search results normally. but when I click on the page number 2..the page refreshes and all the results are gone.

Also I was unable to figure out how can I display the message that there are no search results if the stored procedure returns no rows.

looking forward for help

thanks in advance
Dec 29 '09 #1
0 1452

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Lee | last post by:
Hello all, Fairly new to .net. Using VB.net/2005 I am having a bit of trouble implementing a data driven gridview with paging. I am binding the grid to a DataTable at runtime (which is...
2
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging...
2
by: Jeff | last post by:
Hey ASP.NET 2.0 GridView have AllowPaging & PageSize for the letting the GridView span multiple pages. But is the same allowed on a Repeater control? I didn't see any properties like...
0
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the...
13
by: JJ | last post by:
I have a need to input a large tab delimited text file, which I will parse to check it has the expected columns, before allowing the user to submit it to the database. The user may paste the file...
4
by: zhshqzyc | last post by:
Hi, I am using the paging skills for my page. I'm doing manual databinding (that is, setting the DataSource property, and then calling DataBind()) instead of automatic databinding. So I manually...
2
by: jaredciagar | last post by:
Hi Guys, Please Help ME.... I have a problem in displaying data in my gridview with paging, the data from the database is displaying to my gridview but I want to allow paging in my gridview.how can...
0
JustRun
by: JustRun | last post by:
Hi, This is the first time to work with ASP.NET. I had a customized membership gridview, the problem is i can't enable paging feature or sorting. 1 protected DataSet MyGetAllUsers() 2 ...
16
by: pupilstuff | last post by:
hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric' this is what i did in aspx page <asp:GridView...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
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
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...
0
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...

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.