Home All Groups Group Topic Archive Search About
Author
27 Jan 2006 2:09 AM
bernadou
I’m trying to use the DataList and GridView to accomplish a Parent (or
master), child  type of display (I’ve got that part), but I can’t seem to
figure out how to handle events for the child GridView.  The display looks
like this:

Parent Record
    Child Record [button]
    Child Record [button]
Parent Record   
    Child Record [button]

This was accomplished by dragging and dropping a grid view into the item
template of the DataList that creates the Parent Record, and, setting the
record source on the GridView using a where clause in the SQL that attaches
to a field in the parent record.  All that works great!

Handling the events is killing me.  Usually you can simply go to the code
behind and use the dropdown boxes and VS2005 creates the appropriate event
handlers for your control.  In this case (and if you are with me this far you
might already understand what I’m about to write…) there isn’t an option for
the GridView that makes up my child records.

This is all very strange and I think I understand part of what is happening.
The GridView is now a control of the DataList control (right?), but how do I
work with the click event of the buttons that are created.  I’m stumped.

Thanks for any insight you can provide.

B

Author
27 Jan 2006 3:54 PM
Phillip Williams
I can suggest 2 ways:
1- declaratively define the event handling method, e.g.
OnSelectedIndexChanged="ChildGridView1_SelectedIndexChanged" within the
markup of the grid
2- dynamically, during handling any of the events of the parent control,
normally in your scenario it would be during the DataList.ItemCreated Event,
wire up the event handler to the desired event of the child control.

To see a demo (with source code) that uses both methods (where the nested
controls are GridVeiw->GridVeiw->DetailsVeiw) you may review this demo:
http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx

Show quoteHide quote
"bernadou" wrote:

> I’m trying to use the DataList and GridView to accomplish a Parent (or
> master), child  type of display (I’ve got that part), but I can’t seem to
> figure out how to handle events for the child GridView.  The display looks
> like this:
>
> Parent Record
>     Child Record [button]
>     Child Record [button]
> Parent Record   
>     Child Record [button]
>
> This was accomplished by dragging and dropping a grid view into the item
> template of the DataList that creates the Parent Record, and, setting the
> record source on the GridView using a where clause in the SQL that attaches
> to a field in the parent record.  All that works great!
>
> Handling the events is killing me.  Usually you can simply go to the code
> behind and use the dropdown boxes and VS2005 creates the appropriate event
> handlers for your control.  In this case (and if you are with me this far you
> might already understand what I’m about to write…) there isn’t an option for
> the GridView that makes up my child records.
>
> This is all very strange and I think I understand part of what is happening.
>  The GridView is now a control of the DataList control (right?), but how do I
> work with the click event of the buttons that are created.  I’m stumped.
>
> Thanks for any insight you can provide.
>
> B
>
Author
27 Jan 2006 7:54 PM
bernadou
Phillip,
Hi again.  Thanks for your continued assistance.

I took a look at your example and I get it.  It is slightly different than
what I'm trying to do, but, maybe that is because what I'm trying to do isn't
possible.

Your example hides the child records unless the user clicks the parent row. 
I like this approach, but, it isn't the direction I was going to go.  Your
example allows the parent's selected row index to remain in memory which you
then use to identify the child control to work with the child control events.
All very slick.

I'm unsuccessfully trying to figure out a way to show all the rows (parent
and child) at the same time, and, somehow identify what button from the child
row was clicked.  I may have to just punt and use your approach, but, I'm
wondering if your clearly deeper knowledge on the subject has a quick
suggestion how this might be done.

The crux of the matter is here....

If the user clicks the button at the end of any of the many ChildRows in my
output, the Parent's ItemIndexChanged event doesn't fire (nor has it ever
fired which leaves the parent's item index as Nothing), just the ChildGrid's
ItemIndexChanged fires (atleast based on my debugging attempts). So when I
try this test, I get a Null ref runtime err from the code below:


Protected Sub ChildGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs)

ParentList1.SelectedItem.FindControl("ChildGrid").Visible = False


End Sub

So the question is how to identify the Parent row without actually clicking
the parent row first? (I suspect this isn't possible....)

Thanks once again for your input, it has been extreemly valuable.

Bernie

Show quoteHide quote
"Phillip Williams" wrote:

> I can suggest 2 ways:
> 1- declaratively define the event handling method, e.g.
> OnSelectedIndexChanged="ChildGridView1_SelectedIndexChanged" within the
> markup of the grid
> 2- dynamically, during handling any of the events of the parent control,
> normally in your scenario it would be during the DataList.ItemCreated Event,
> wire up the event handler to the desired event of the child control.
>
> To see a demo (with source code) that uses both methods (where the nested
> controls are GridVeiw->GridVeiw->DetailsVeiw) you may review this demo:
> http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx
>
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "bernadou" wrote:
>
> > I’m trying to use the DataList and GridView to accomplish a Parent (or
> > master), child  type of display (I’ve got that part), but I can’t seem to
> > figure out how to handle events for the child GridView.  The display looks
> > like this:
> >
> > Parent Record
> >     Child Record [button]
> >     Child Record [button]
> > Parent Record   
> >     Child Record [button]
> >
> > This was accomplished by dragging and dropping a grid view into the item
> > template of the DataList that creates the Parent Record, and, setting the
> > record source on the GridView using a where clause in the SQL that attaches
> > to a field in the parent record.  All that works great!
> >
> > Handling the events is killing me.  Usually you can simply go to the code
> > behind and use the dropdown boxes and VS2005 creates the appropriate event
> > handlers for your control.  In this case (and if you are with me this far you
> > might already understand what I’m about to write…) there isn’t an option for
> > the GridView that makes up my child records.
> >
> > This is all very strange and I think I understand part of what is happening.
> >  The GridView is now a control of the DataList control (right?), but how do I
> > work with the click event of the buttons that are created.  I’m stumped.
> >
> > Thanks for any insight you can provide.
> >
> > B
> >
Author
27 Jan 2006 8:56 PM
Phillip Williams
Hi Bernie,

I think that what you are attempting is possible to be done.  If you post
the entire code of your datalist that contains those other controls I might
get a more accurate description of the challenge you face in completing your
design.
Show quoteHide quote
"bernadou" wrote:

> Phillip,
> Hi again.  Thanks for your continued assistance.
>
> I took a look at your example and I get it.  It is slightly different than
> what I'm trying to do, but, maybe that is because what I'm trying to do isn't
> possible.
>
> Your example hides the child records unless the user clicks the parent row. 
> I like this approach, but, it isn't the direction I was going to go.  Your
> example allows the parent's selected row index to remain in memory which you
> then use to identify the child control to work with the child control events.
>  All very slick.
>
> I'm unsuccessfully trying to figure out a way to show all the rows (parent
> and child) at the same time, and, somehow identify what button from the child
> row was clicked.  I may have to just punt and use your approach, but, I'm
> wondering if your clearly deeper knowledge on the subject has a quick
> suggestion how this might be done.
>
> The crux of the matter is here....
>
> If the user clicks the button at the end of any of the many ChildRows in my
> output, the Parent's ItemIndexChanged event doesn't fire (nor has it ever
> fired which leaves the parent's item index as Nothing), just the ChildGrid's
> ItemIndexChanged fires (atleast based on my debugging attempts). So when I
> try this test, I get a Null ref runtime err from the code below:
>
>
> Protected Sub ChildGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e
> As System.EventArgs)
>
> ParentList1.SelectedItem.FindControl("ChildGrid").Visible = False
>
>        
>  End Sub
>
> So the question is how to identify the Parent row without actually clicking
> the parent row first? (I suspect this isn't possible....)
>
> Thanks once again for your input, it has been extreemly valuable.
>
> Bernie
>
> "Phillip Williams" wrote:
>
> > I can suggest 2 ways:
> > 1- declaratively define the event handling method, e.g.
> > OnSelectedIndexChanged="ChildGridView1_SelectedIndexChanged" within the
> > markup of the grid
> > 2- dynamically, during handling any of the events of the parent control,
> > normally in your scenario it would be during the DataList.ItemCreated Event,
> > wire up the event handler to the desired event of the child control.
> >
> > To see a demo (with source code) that uses both methods (where the nested
> > controls are GridVeiw->GridVeiw->DetailsVeiw) you may review this demo:
> > http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx
> >
> > --
> > HTH,
> > Phillip Williams
> > http://www.societopia.net
> > http://www.webswapp.com
> >
> >
> > "bernadou" wrote:
> >
> > > I’m trying to use the DataList and GridView to accomplish a Parent (or
> > > master), child  type of display (I’ve got that part), but I can’t seem to
> > > figure out how to handle events for the child GridView.  The display looks
> > > like this:
> > >
> > > Parent Record
> > >     Child Record [button]
> > >     Child Record [button]
> > > Parent Record   
> > >     Child Record [button]
> > >
> > > This was accomplished by dragging and dropping a grid view into the item
> > > template of the DataList that creates the Parent Record, and, setting the
> > > record source on the GridView using a where clause in the SQL that attaches
> > > to a field in the parent record.  All that works great!
> > >
> > > Handling the events is killing me.  Usually you can simply go to the code
> > > behind and use the dropdown boxes and VS2005 creates the appropriate event
> > > handlers for your control.  In this case (and if you are with me this far you
> > > might already understand what I’m about to write…) there isn’t an option for
> > > the GridView that makes up my child records.
> > >
> > > This is all very strange and I think I understand part of what is happening.
> > >  The GridView is now a control of the DataList control (right?), but how do I
> > > work with the click event of the buttons that are created.  I’m stumped.
> > >
> > > Thanks for any insight you can provide.
> > >
> > > B
> > >
Author
28 Jan 2006 4:17 PM
bernadou
Thanks for the offer.  I'm on a different thing at the moment.  When I return
to this issue I'll post a simplified version of the code that I'm trying to
work with so you might have a more accurate picture of the issue.

Thanks a ton for your help, and, the great examples on your site.  Truly
excellent work.

B

Show quoteHide quote
"Phillip Williams" wrote:

> Hi Bernie,
>
> I think that what you are attempting is possible to be done.  If you post
> the entire code of your datalist that contains those other controls I might
> get a more accurate description of the challenge you face in completing your
> design.
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "bernadou" wrote:
>
> > Phillip,
> > Hi again.  Thanks for your continued assistance.
> >
> > I took a look at your example and I get it.  It is slightly different than
> > what I'm trying to do, but, maybe that is because what I'm trying to do isn't
> > possible.
> >
> > Your example hides the child records unless the user clicks the parent row. 
> > I like this approach, but, it isn't the direction I was going to go.  Your
> > example allows the parent's selected row index to remain in memory which you
> > then use to identify the child control to work with the child control events.
> >  All very slick.
> >
> > I'm unsuccessfully trying to figure out a way to show all the rows (parent
> > and child) at the same time, and, somehow identify what button from the child
> > row was clicked.  I may have to just punt and use your approach, but, I'm
> > wondering if your clearly deeper knowledge on the subject has a quick
> > suggestion how this might be done.
> >
> > The crux of the matter is here....
> >
> > If the user clicks the button at the end of any of the many ChildRows in my
> > output, the Parent's ItemIndexChanged event doesn't fire (nor has it ever
> > fired which leaves the parent's item index as Nothing), just the ChildGrid's
> > ItemIndexChanged fires (atleast based on my debugging attempts). So when I
> > try this test, I get a Null ref runtime err from the code below:
> >
> >
> > Protected Sub ChildGrid_SelectedIndexChanged(ByVal sender As Object, ByVal e
> > As System.EventArgs)
> >
> > ParentList1.SelectedItem.FindControl("ChildGrid").Visible = False
> >
> >        
> >  End Sub
> >
> > So the question is how to identify the Parent row without actually clicking
> > the parent row first? (I suspect this isn't possible....)
> >
> > Thanks once again for your input, it has been extreemly valuable.
> >
> > Bernie
> >
> > "Phillip Williams" wrote:
> >
> > > I can suggest 2 ways:
> > > 1- declaratively define the event handling method, e.g.
> > > OnSelectedIndexChanged="ChildGridView1_SelectedIndexChanged" within the
> > > markup of the grid
> > > 2- dynamically, during handling any of the events of the parent control,
> > > normally in your scenario it would be during the DataList.ItemCreated Event,
> > > wire up the event handler to the desired event of the child control.
> > >
> > > To see a demo (with source code) that uses both methods (where the nested
> > > controls are GridVeiw->GridVeiw->DetailsVeiw) you may review this demo:
> > > http://www.webswapp.com/CodeSamples/aspnet20/GridView_1c.aspx
> > >
> > > --
> > > HTH,
> > > Phillip Williams
> > > http://www.societopia.net
> > > http://www.webswapp.com
> > >
> > >
> > > "bernadou" wrote:
> > >
> > > > I’m trying to use the DataList and GridView to accomplish a Parent (or
> > > > master), child  type of display (I’ve got that part), but I can’t seem to
> > > > figure out how to handle events for the child GridView.  The display looks
> > > > like this:
> > > >
> > > > Parent Record
> > > >     Child Record [button]
> > > >     Child Record [button]
> > > > Parent Record   
> > > >     Child Record [button]
> > > >
> > > > This was accomplished by dragging and dropping a grid view into the item
> > > > template of the DataList that creates the Parent Record, and, setting the
> > > > record source on the GridView using a where clause in the SQL that attaches
> > > > to a field in the parent record.  All that works great!
> > > >
> > > > Handling the events is killing me.  Usually you can simply go to the code
> > > > behind and use the dropdown boxes and VS2005 creates the appropriate event
> > > > handlers for your control.  In this case (and if you are with me this far you
> > > > might already understand what I’m about to write…) there isn’t an option for
> > > > the GridView that makes up my child records.
> > > >
> > > > This is all very strange and I think I understand part of what is happening.
> > > >  The GridView is now a control of the DataList control (right?), but how do I
> > > > work with the click event of the buttons that are created.  I’m stumped.
> > > >
> > > > Thanks for any insight you can provide.
> > > >
> > > > B
> > > >