473,664 Members | 2,797 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EnableViewSo urce = true;
gv.PageIndexCha nging += new
GridViewPageEve ntHandler(gv_Pa geIndexChanging );
gv.Datasource = //bind it to my datasource
gv.Databind(); //databind

And in my PageIndex event:
private void gv_PageIndexCha nging(object sender, GridViewPageEve ntArgs
e)
{
// Set the CurrentPageInde x before binding the grid
Gridview gv = (GridView) sender;
gv.PageIndex = e.NewPageIndex;

gv.DataBind();

}

May 9 '07 #1
2 11981
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.EnableViewSo urce = true;
gv.PageIndexCha nging += new
GridViewPageEve ntHandler(gv_Pa geIndexChanging );
gv.Datasource = //bind it to my datasource
gv.Databind(); //databind

And in my PageIndex event:
private void gv_PageIndexCha nging(object sender, GridViewPageEve ntArgs
e)
{
// Set the CurrentPageInde x 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 PageIndexChange d
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
PageIndexChange d 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.LoadContro l() 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 PageIndexChange d 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
16335
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.
6
6504
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 button (next, last, or page #), it return this error and I don't know what's wrong: Source Error: An unhandled exception was generated during the execution of the
1
7005
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 anyone have any idea how to get this to work? below is the code. Please bear in mind that the function is actually located in a seperate class file from the page that actually returns the grid. ---code for function that returns the grid, this is...
1
2941
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 when I page the GridView (the paging controllers are in the gridview's footer). The webpage doesnt scroll back to the top of the page, so when paging through the GridView the user is always looking at the last 4-5 items on the page. My current...
6
2741
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. I did that and it works fine. But, the problem is that I use atlas control updatePanel on my page, when I place gridView in that control, paging stops working. It does not throw any exceptions. But there is a small icon in the status bar that...
9
7920
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 contains a placeholder and I add the control to it, the user control is a formview bound to an object datsource. This works great until I post back the page and the user control disappears. What am I doing wrong? Regards, Chris. Protected Sub...
1
2039
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 to view other records. For that I have given the coding as protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } ...
2
5386
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 GridView1_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) {
4
8823
by: Peter | last post by:
I want to call a JavaScript on PageIndexChanged event, how do I do that? Thank You Peter
0
8437
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
8861
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
8636
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...
0
7375
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
6187
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
4185
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
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1759
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.