473,378 Members | 1,377 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,378 software developers and data experts.

Dynamically Created Gridview - Paging events are not fired

ami
In my code, I need to implement x numbers of Gridviews dynamically
based on user selection. Because I am unaware of the number of
gridviews, this is done after the user enters input.

I need to implement paging on these gridviews. I set paging to true
and register the event handler. However, this event handler is never
being fired (this has been tested by using the VS2005 debugger). My
first page of results shows up fine. When a page button is clicked
(to go to page 2, for example), the table disappears. Any help would
be appreciated.

Here are some snippets of my code (from my code behind page):
Gridview gv = new Gridview();
gv.AllowPaging = true;
gv.EnableViewSource = true;
gv.PageIndexChanging += new
GridViewPageEventHandler(gv_PageIndexChanging);
gv.Datasource = //bind it to my datasource
gv.Databind(); //databind

And in my PageIndex event:
private void gv_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
// Set the CurrentPageIndex before binding the grid
Gridview gv = (GridView) sender;
gv.PageIndex = e.NewPageIndex;

gv.DataBind();

}

May 9 '07 #1
2 11964
you need to re-add the grids and event hooksups in the oninit of the
next postback.

-- bruce (sqlwork.com)

ami wrote:
In my code, I need to implement x numbers of Gridviews dynamically
based on user selection. Because I am unaware of the number of
gridviews, this is done after the user enters input.

I need to implement paging on these gridviews. I set paging to true
and register the event handler. However, this event handler is never
being fired (this has been tested by using the VS2005 debugger). My
first page of results shows up fine. When a page button is clicked
(to go to page 2, for example), the table disappears. Any help would
be appreciated.

Here are some snippets of my code (from my code behind page):
Gridview gv = new Gridview();
gv.AllowPaging = true;
gv.EnableViewSource = true;
gv.PageIndexChanging += new
GridViewPageEventHandler(gv_PageIndexChanging);
gv.Datasource = //bind it to my datasource
gv.Databind(); //databind

And in my PageIndex event:
private void gv_PageIndexChanging(object sender, GridViewPageEventArgs
e)
{
// Set the CurrentPageIndex before binding the grid
Gridview gv = (GridView) sender;
gv.PageIndex = e.NewPageIndex;

gv.DataBind();

}
May 10 '07 #2
I'm having a similar problem but in my case the grid does not disappear
(as I do all the initialization on Page_Init()) but it just reloads the
page and nothing changes.

If I trace through the code I can clearly see that the PageIndexChanged
event is never being fired. Which is weird considering that doing the
same with, for example, the Click event of a button it works fine.

Another important detail is that this happens only when loading the
control dynamically.

In my case I have a UserControl that contains a GridView. The GridView
is being initialized during the Init event of the UserControl and the
PageIndexChanged event is being hooked to a function in that control's
code.

Then I create the control on my aspx page by using the
Page.LoadControl() method and assign the result to the Controls
collection of a placeholder that I placed on that page.

The result is that if I do like that, events like PageIndexChanged do
not fire.

If, instead, I drag & drop the user control that I've created into the
page and then make it run, it works fine.

Has anyone got any idea about the reason of this behavior?

Thanks!

Valerio

bruce barker wrote:
you need to re-add the grids and event hooksups in the oninit of the
next postback.

-- bruce (sqlwork.com)

ami wrote:
>In my code, I need to implement x numbers of Gridviews dynamically
based on user selection. Because I am unaware of the number of
gridviews, this is done after the user enters input.

I need to implement paging on these gridviews. I set paging to true
and register the event handler. However, this event handler is never
being fired (this has been tested by using the VS2005 debugger). My
first page of results shows up fine. When a page button is clicked
(to go to page 2, for example), the table disappears. Any help would
be appreciated.
May 30 '07 #3

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

Similar topics

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...
6
by: Carlos Albert | last post by:
Hi everybody, I'm working with a gridview (4 bound columns and 1 template column, using databind from codebehind). It works just fine, but I tried to add paging, and when I click any paging...
1
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does...
1
by: davidjgonzalez | last post by:
I have a GridView that has paging enabled. Each item (as defined in an ItemTemplate) includes several controls which have operations i would like to Atlas-enable. Everything is working well except...
6
by: Slavan | last post by:
Hello everyone, I have a gridView on my page that I bind to a dataTable in my code behind. I know that when I do that I need to implement pageIndexChanging event for paging functionality to work....
9
by: Chris | last post by:
I am dynamically adding a user control to each row in a gridview. The reason I am doing it dynamically is the user control is different depending on certain data in the gridview. The gridview...
1
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have...
2
by: gnewsgroup | last post by:
I have a GridView, in which the header of one column changes depending on the selected value of a DropDownList outside of this GridView. I did this dynamic header through protected void...
4
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.