473,611 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Paging in Gridview with datatable

112 New Member
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 1464

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

Similar topics

2
1679
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 created on the fly) as opposed to setting up a datasource on the page, etc. I create the datatable and then assign it to the gridview's datasource property and call DataBind.
2
16333
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 feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
2
2230
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 AllowPaging or PageSize on the Repeater control, so I guess it isn't possible? if it is possible maybe somebody here could give me a tip on how
0
2000
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 paging tools causes the GridView to completely disappear! This happens when either DataSets or DataTables are used (it doesn't work at all for DataReaders because they don't support paging apparently). If you remove the...
13
2794
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 into a textbox, or upload it (haven't decided yet). The problem I have is that the text file consists of around 3000 lines, and I want to display the formatted columns to the user before submitting it to the database (perhaps allowing them to...
4
2981
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 handle events for paging. But the page is invisible. Thanks for your help. protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { DataSet myDataSet = new DataSet(); ...
2
2788
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 I do that? I got an error msg that datareader does not allow paging in gridview.... because I use datareader in binding my data. How can I convert my datareader to datatable using VB script so that I can allow paging to my Gridview? I'm Using...
0
1142
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 { 3 DataSet ds = new DataSet(); 4
16
4003
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 ID="TableGridView" OnPageIndexChanging="TableGridView_PageIndexChanging" runat="server" AutoGenerateColumns="False"
0
8149
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8097
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8596
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7038
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6072
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4042
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4108
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1411
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.