RowCommand Event of a nested Gridview


N

NEO

How do I handle the RowCommand event for a nested gridview? I want to be able
to detect which command (edit or delete) for the child gridview and the row
that raised the event. I don't have problems with the parent gridview.
 
Ad

Advertisements

B

Brennan Stehling

I assume you are having a problem with the Design Mode to get at the
Events listing in the Properties window. That is a problem.

In this case what I do is handle the RowDataBound event. In there I
can get to the Cell holding the embedded controls and set values on
them. In your case, you want to reach into it and attach an event
handler. You need to do it programatically since you cannot do it with
the designer.

Then you want to set the CommandName and CommandArgument values of your
button controls so that when the RowCommand event is raised you can
check those values to determine what to do.

Using an embedded GridView within a GridView entails many caveats. You
are going to have to be careful. And be sure to run through it a bit
with the debugger to understand what is actually doing. What you
expect it would do can often be something very different than what is
actually doing. That has bitten me plenty as I have worked with
ASP.NET.

Brennan Stehling
http://brennan.offwhite.net/blog/
 

Top