Trying to implement master/detail with 2 datagrids

B

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
 
B

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
}
}
 
B

Buddy Robbins

Hey Brock,

Thanks for the assist. That did the trick!

-Buddy Robbins


Brock Allen said:
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
}
}




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
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top