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

datagrid command events not firing.

I have an interesting problem with a datagrid. It is the standard
chicken-and-the-egg problem.

I have this page with two datagrids. It essentially defines a parent-child
relationship. The parent grid has a "edit" and "delete" columns. When the
"edit" link button is clicked, I want the child grid to display some
information related to the parent. Now the child grid also has some command
buttons.

My problem is that I cannot get the child grid to responded to the command
events. The handlers are never invoked. Here is what I think the problem
is. In order for the handlers to be invoked, the object model for the past
must be the same on postback as was sent to the browser. That means that I
have to initialize both grids their Init events so the command handlers will
be invoked. The problem is, that when the parent grid's edit button is
clicked, the Init fires as expected, but I do not know the ID for the item
that was selected until the EditCommand handler is invoked. At this point,
I could bind the grid and render the appropriate list items. But, if I do
this, then if a command link is clicked on the child grid, the events do not
fire since the grid was not built in the Init event.

Any ideas at how I can solve this, assuming I made any sense?
Nov 19 '05 #1
1 2085
One of my co-workers just ran into this problem yesterday.

First, make sure the sub that should fire has the 'handles' directive at
the very right of the 'sub ...' line.

For example:
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.EditCommand
Also .. be sure you are NOT binding the datagrid on post-backs.

If you are running code (or calling a sub) in the page_load that does
your data-binding, be sure to exclude it from postbacks. Like this:

If Not IsPostBack Then
.. DB CODE ..
End If

Hope that helps,
Ricky

Peter Rilling wrote:
I have an interesting problem with a datagrid. It is the standard
chicken-and-the-egg problem.

I have this page with two datagrids. It essentially defines a parent-child
relationship. The parent grid has a "edit" and "delete" columns. When the
"edit" link button is clicked, I want the child grid to display some
information related to the parent. Now the child grid also has some command
buttons.

My problem is that I cannot get the child grid to responded to the command
events. The handlers are never invoked. Here is what I think the problem
is. In order for the handlers to be invoked, the object model for the past
must be the same on postback as was sent to the browser. That means that I
have to initialize both grids their Init events so the command handlers will
be invoked. The problem is, that when the parent grid's edit button is
clicked, the Init fires as expected, but I do not know the ID for the item
that was selected until the EditCommand handler is invoked. At this point,
I could bind the grid and render the appropriate list items. But, if I do
this, then if a command link is clicked on the child grid, the events do not
fire since the grid was not built in the Init event.

Any ideas at how I can solve this, assuming I made any sense?

Nov 19 '05 #2

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

Similar topics

0
by: Timothy Elvidge | last post by:
I have an DataGrid with AutoGenerateColumns False and two controls defined for OnSort a third column contains a ButtonColum to add items to a basket.None of the relevant eventhandlers fire. I have...
5
by: John Richardson | last post by:
I've been bothered for some time about my DataGrid not populating my rows very quickly. I have about 10K rows loading into the grid. I create a datatable dt with 2 columns, an ID and a display. ...
8
by: Brent Burkart | last post by:
My datagrid OnCancelCommand event is not firing. HTML OnCancelCommand="AdminGrid_Cancel" 'Code Behind Sub AdminGrid_Cancel(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)...
2
by: vinay | last post by:
I implemented paging on this grid OnPageIndexChanged="dgSales_Page" When i click Next page, it is firing OnItemCommand insted of OnPageIndexChanged ??? <asp:datagrid id="dgSales"...
2
by: saleek | last post by:
Hi, I am trying to figure out why my datagrid has stopped firing the page and sort commands. Scenario: I originally had template columns in my datagrid and had set up custom bi-directional...
1
by: Stu | last post by:
Hi, I have a button in the footer of a datagrid that sometimes does not tigger the item command. The page is quite large & has a number of homegrown controls in it. Has anyone come across this...
2
by: Deepesh | last post by:
Good day, I have a specific case of the DataGrid in my solution which is causing the ItemCommand Event Not Firing. So I'm creating a "Skinnable" set of controls. I seperate the actual ASCX file...
2
by: Lagwagon | last post by:
I have an Image Button inside of a Datagrid and its not firing the datagrid.itemcommand event when it is clicked. Does anyone have a link to a tutorial or a solution for this problem? For my...
2
by: AdrEsqu | last post by:
I am trying to use AutoPostback to retrieve the value that was selected in my dropdownlist. The event is not firing for the dropdownlist because the datagrid is being built after the Lifecycle...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
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,...
0
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,...

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.