Home All Groups Group Topic Archive Search About

Trying to implement master/detail with 2 datagrids

Author
28 Mar 2005 11:26 PM
Buddy Robbins
I am trying to implement a master/detail type page in ASP.Net (VB) using 2
datagrids.
I would like to make it so when you click on a row in the master, the
postback happens, the dataview for the detail is filtered on the master row
selected.

In the master's ItemDataBound event, I add an onclick event calling the
GetPostBackClientEvent
    e.Item.Attributes("onclick") = Page.GetPostBackClientEvent(e.Item,
e.Item.Cells(1).Text)


but I can't figure out how to get my GUID from client back to the server to
set the dataview filter.  In the code, the e.item.Cells(1).text is the Guid,
but it's getting lost.

Can anyone give me a good suggestion?

Thanks in advance,
-Buddy Robbins

Author
28 Mar 2005 11:36 PM
Brock Allen
I'd use the DatraGrid's DataKeyField property to let it track the PK for
the rows. For the postback, I'd suggest adding a LinkButton (or normal Button)
and specifiy the CommandName="Select" (or some other string that makes sense
to you). Then the event to handle is the DataGrid's ItemCommand event. It
passes a DataGridItemEventArgs which has a CommandName property -- this should
be your LinkButton's CommandName. If it's "Select" then you have the row
via DataGridItemEventArgs.Item property. The PK is just then one more step
away via DataGrid.DataKeys[DataGridItemEventArgs.Item.ItemIndex]. Here's
a snippet:

private void _grid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs
e)
{
    if (e.CommandName == "Select")
    {
        object pk = _grid.DataKeys[e.Item.ItemIndex];
        // use pk to seed second DataGrid
    }
}

-Brock
DevelopMentor
http://staff.develop.com/ballen



Show quoteHide quote
> I am trying to implement a master/detail type page in ASP.Net (VB)
> using 2
> datagrids.
> I would like to make it so when you click on a row in the master, the
> postback happens, the dataview for the detail is filtered on the
> master row
> selected.
> In the master's ItemDataBound event, I add an onclick event calling
> the
> GetPostBackClientEvent
> e.Item.Attributes("onclick") = Page.GetPostBackClientEvent(e.Item,
> e.Item.Cells(1).Text)
> but I can't figure out how to get my GUID from client back to the
> server to set the dataview filter.  In the code, the
> e.item.Cells(1).text is the Guid, but it's getting lost.
>
> Can anyone give me a good suggestion?
>
> Thanks in advance,
> -Buddy Robbins
Author
29 Mar 2005 6:13 PM
Buddy Robbins
Hey Brock,

Thanks for the assist.  That did the trick!

-Buddy Robbins


Show quoteHide quote
"Brock Allen" <ballen@NOSPAMdevelop.com> wrote in message
news:289314632476318097402576@msnews.microsoft.com...
> I'd use the DatraGrid's DataKeyField property to let it track the PK for
> the rows. For the postback, I'd suggest adding a LinkButton (or normal
> Button) and specifiy the CommandName="Select" (or some other string that
> makes sense to you). Then the event to handle is the DataGrid's
> ItemCommand event. It passes a DataGridItemEventArgs which has a
> CommandName property -- this should be your LinkButton's CommandName. If
> it's "Select" then you have the row via DataGridItemEventArgs.Item
> property. The PK is just then one more step away via
> DataGrid.DataKeys[DataGridItemEventArgs.Item.ItemIndex]. Here's a snippet:
>
> private void _grid_ItemCommand(object source,
> System.Web.UI.WebControls.DataGridCommandEventArgs e)
> {
> if (e.CommandName == "Select")
> {
> object pk = _grid.DataKeys[e.Item.ItemIndex];
> // use pk to seed second DataGrid
> }
> }
>
> -Brock
> DevelopMentor
> http://staff.develop.com/ballen
>
>
>
>> I am trying to implement a master/detail type page in ASP.Net (VB)
>> using 2
>> datagrids.
>> I would like to make it so when you click on a row in the master, the
>> postback happens, the dataview for the detail is filtered on the
>> master row
>> selected.
>> In the master's ItemDataBound event, I add an onclick event calling
>> the
>> GetPostBackClientEvent
>> e.Item.Attributes("onclick") = Page.GetPostBackClientEvent(e.Item,
>> e.Item.Cells(1).Text)
>> but I can't figure out how to get my GUID from client back to the
>> server to set the dataview filter.  In the code, the
>> e.item.Cells(1).text is the Guid, but it's getting lost.
>>
>> Can anyone give me a good suggestion?
>>
>> Thanks in advance,
>> -Buddy Robbins
>
>
>