473,545 Members | 721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic Datagrid, Strange Paging Issue

1 New Member
I have a dynamically created datagrid, populated from a dataset that is filled by a sql string triggered by a command button. The application itself allows a user to input a selection of criteria and hit search, the results ome back in the grid.

Due to the probably amount of records that will be returd, I decided to allow paging to make the data more visually appealing. So far, so good. Everything is running smoothly until.. you try to selct a new page on the datagrid. The grid just disappears!!!

here is the vb code that populates the datagrid.
Expand|Select|Wrap|Line Numbers
  1.     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
  2.         con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\Chris\Desktop\incidents.mdb"
  3.         con.Open()
  4.         sql = "SELECT * FROM tbl_incidents WHERE Address Like '%" & txtAddress.Text & "%' And Borough Like '%" & ddlborough.SelectedValue & "%'"
  5.         da = New OleDb.OleDbDataAdapter(sql, con)
  6.         da.Fill(ds, "incidents")
  7.         GridView1.DataSource = ds.Tables("incidents")
  8.         GridView1.DataBind()
  9.         con.Close()
  10.     End Sub
and here is how I have been handling the pageindexchangi ng:
Expand|Select|Wrap|Line Numbers
  1.     Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
  2.         GridView1.PageIndex = e.NewPageIndex
  3.         If Page.IsPostBack Then
  4.             GridView1.DataSource = ds.Tables("incidents")
  5.             GridView1.DataBind()
  6.         End If
  7.     End Sub
  8.  
I have tried this various ways, the latest handling the postback as I believe that this was causing the issue but the results are the same.

An odd thing is that I have a clear button on the app which clears any text in textboxes left over from the search and resets the drop down lists to their defaults. On click, the gridview re-appears again on the page you requested when you lost it, however, it has the records from the first page in it still.

I cannot for the life of me solve this issue and I would be forever grateful for a solution.

Thanks
Mar 17 '09 #1
1 1763
BeemerBiker
87 New Member
IANE, but I will take a stab at this because I had the same problem.

I assume you have "EnableViewStat e" set to true for the gridview. You do not need any of the code you got in that PageIndexChangi ng. If you have some unbound checkboxes you might want to use that callback to preserve them so they can be repopulated.

When the page loads the first time (IsPostBack false) you should call some routine that populates the grid and saves the sql command so it can be reused in the postback. I had the function "FormSqlCommand " and it stored the sql command in the tooltip for my "search" button (which is also EnableViewState = true). The callback for my "search" button also executed that same FormSqlCommand since it gathered all the filter parameters that were to go into the sql command. Thus after the callback was executed, the tooltip was always set to the correct sql select command and the IsPostBack true was able to get access to that string. All I did in the postback true was to set
SqlDataSource1. SelectCommand = btnExecuteSearc h.ToolTip.ToStr ing():
Want to point out that I could have used a session variable, but the tooltip was nice because I could look at the command and debug it visually.

Your case you are filling in a dataset. You could store the dataset into a session variable and then on postback, set the dataset to the session variable and rebind the grid. You should not have to do any GridView1.PageI ndex = e.NewPageIndex as the paging is handled automatically.

Someone may have a cleaner way.

HTH
Mar 17 '09 #2

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

Similar topics

0
1336
by: Clement | last post by:
I have an user control(Control1) that dynamically adds another user control(Control2). In Control2, I am displaying data in a datagrid which I enable paging and sorting. When I click on the page number, there is a javascript error: Object Expected. I searched this group for solutions, I found a similar problem ...
1
7547
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
2
1974
by: michele | last post by:
Hi, i'm using a datagrid control in my webform, with AutoGenerateColumns=false; it work very well if EnableViewState=true; including paging and sorting, but this cause a big performance issue, so i've decided to set EnableViewState=false: now the events related to the datagrid have some strange behavours: for example the PageIndexChangedEvent...
4
2102
by: Manny Chohan | last post by:
hi guys, my code is returning an array and i need to create datagrid so that i can have sorting and implement prev....next function on it to navigate. is there any way this can be done in codebehind file. I am using c#. Thanks Manny
2
2570
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 to be scrolled down completely to see the page number links. The page number should always be visible outside the scroll bar. Basically I want to...
8
1905
by: Jeff | last post by:
Hi - I'm having trouble Databinding a SQLDataReader to a DataGrid control. I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in a directory of my localhost on my development machine. The database is on the web. When I run the app on the local machine, IE opens, loads my aspx page from...
0
1386
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, previous page, next page and last page. The buttoms are created like: CODE 'configure the link buttons link_1.ID = "f_link" link_2.ID = "p_link"
0
1308
by: rn5a | last post by:
In a shopping cart app, a user purchases 5 items on 31st March 2007. This is his 1st order. He places a 2nd order on 13th April in which he buys 8 items. Next he places his 3rd order on 16th April in which he buys 2 items. The details of the orders are displayed in a DataGrid but I want to display only 1 order in one page. In other words, I...
7
2318
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
The default paging behavior of the gridview doesn't work well with very large sets of data which means we have to implement some sort of custom paging. The examples I have seen (4guysfromrolla, etc.) suggest using an ObjectDataSource which has built-in paging functionality that, when used in conjunction with certain SQL 2005 functionality,...
0
7398
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...
0
7805
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5325
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...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
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...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
701
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...

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.