datagrid command events not firing.

P

Peter Rilling

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?
 
R

Ricky Smith

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top