473,805 Members | 1,910 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGrid paging

Hello everybody, I got myself a strange problem

I have a DataGrid in the page, nothing special about it, only it connects datasource programatically and it supports paging.y. So the code is something like this

private void Page_Load(objec t sender, System.EventArg s e

if (!IsPostBack
GridBind()

private void GridBind(

myGrid..DataSou rce = GetSomeDataSour ce()
myGrid.DataBind ()

private void PageChanged(obj ect source, System.Web.UI.W ebControls.Data GridPageChanged EventArgs e

myGrid.CurrentP ageIndex = e.NewPageIndex
BindData()
This worked perfectly OK. Then I decided to try also to create grid columns dynamically. So I set the AutoGenerateCol umns property to false. I changed the code, so it would create some columns like this

private void Page_Load(objec t sender, System.EventArg s e

AddSomeColumnsT oGrid();

if (!IsPostBack
GridBind()
Now when I load the page for the 1st time, everything is OK. When I want to go to another page grid mystically disappears. I tried to debug the page setting breakpoint inside the PageChanged event and I never got there
Being desperate I tried everything possible then I came to something like this

private void Page_Load(objec t sender, System.EventArg s e

AddSomeColumnsT oGrid();

//if (!IsPostBack
GridBind()
and it worked. But now I am creating dataset 2 times in postback (supposing it's the page changed event)

Am I doing anything wrong? Because I really don't know how to solve this problem. Any helps would be very appreciated.
Nov 18 '05 #1
4 1431
I made some errors in the first source code, it should be this

private void Page_Load(objec t sender, System.EventArg s e

if (!IsPostBack
GridBind()

private void GridBind(

myGrid.DataSour ce = GetSomeDataSour ce()
myGrid.DataBind ()

private void PageChanged(obj ect source, System.Web.UI.W ebControls.Data GridPageChanged EventArgs e

myGrid.CurrentP ageIndex = e.NewPageIndex
GridBind()
Nov 18 '05 #2
I made some errors in the first source code, it should be this

private void Page_Load(objec t sender, System.EventArg s e

if (!IsPostBack
GridBind()

private void GridBind(

myGrid.DataSour ce = GetSomeDataSour ce()
myGrid.DataBind ()

private void PageChanged(obj ect source, System.Web.UI.W ebControls.Data GridPageChanged EventArgs e

myGrid.CurrentP ageIndex = e.NewPageIndex
GridBind()
Nov 18 '05 #3
Add the AddSomeColumnsT oGrid() method to the GridBind method. That way, any time you are going to bind the grid you know you have the columns.
Nov 18 '05 #4
I tried what you suggested, but the problem stays. Let's revisit the code once more (as you proposed):

private void Page_Load(objec t sender, System.EventArg s e)
{
if (!IsPostBack)
GridBind();
}
private void GridBind()
{
AddSomeColumnsT oGrid();

myGrid.DataSour ce = GetSomeDataSour ce();
myGrid.DataBind ();
}
private void PageChanged(obj ect source, System.Web.UI.W ebControls.Data GridPageChanged EventArgs e)
{
myGrid.CurrentP ageIndex = e.NewPageIndex;
GridBind();
}

Again it works OK when the page is loading for the 1st time. When I try to get another page, grid is gone. Debugging the project I found out that the execution never reaches the PageChanged handler. That is what confuses me mostly.

Because when I comment the line in Page_load like this:

private void Page_Load(objec t sender, System.EventArg s e)
{
// if (!IsPostBack)
GridBind();
}

it works. But now, unfortunately, the grid shows 2 copies of columns, logically, because I added them twice.

Resolution - the biggest problem as I see it is, that the execution is not passed to the handler of PageChanged event when postback occures, when I hit page number at the bottom of the grid.

This is pretty weird, I know. But that is why the solution is not easy to find in ANY help. Thanks in advance for further suggestions.
Nov 18 '05 #5

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

Similar topics

2
2587
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 create the paging links dynamically and on click of this it should fire PageIndexChanged event.
6
1816
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 fills the temp table again and returns rows 10-19. The temp table is dropped after each call to the SP, so it has to be created and filled every time the user changes page in the datagrid. My question is this: Would it be more efficient to...
2
1864
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 navigation links use JavaScript to jump between pages. I want them to use standard hyperlinks providing the page number in some URL parameter so that I can copy the hyperlink elsewhere.
5
2797
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 to the database to get the next page. Is there a way to use the dataset to allow us to read back and forth in it instead of going back to the database to get it? Thanks,
0
1346
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 populates the data in the Details DataGrid (I'm using Dim Filter As String = CStr(dtgMaster.DataKeys(dtgMaster.SelectedIndex)).Replace("'", "''") to filter btw the Datagrids)
0
9716
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
10607
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
10104
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7645
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
5541
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
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4317
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
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
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.