Get Data from one Grid to another

K

Karl Napp

I have two tables:
The first is "house" with the columns "house_id" and "house_name".
The second is "room" with "house_id", "room_id", "room_name".

Now, I have two DataGrids. The first should only show the "house_name" and
OnClick it should be able to send the "house_id" to a method that will fill
the second DataGrid.

I have tried <asp:buttoncolumn datatextfield="house_name"> to show the name
but I am not able to retrieve the id to send it to my method :-(


Any help appreciated,
KN
 
J

Jos

Karl said:
I have two tables:
The first is "house" with the columns "house_id" and "house_name".
The second is "room" with "house_id", "room_id", "room_name".

Now, I have two DataGrids. The first should only show the
"house_name" and OnClick it should be able to send the "house_id" to
a method that will fill the second DataGrid.

I have tried <asp:buttoncolumn datatextfield="house_name"> to show
the name but I am not able to retrieve the id to send it to my method
:-(

Set DataKeyField="house_id" for the first datagrid.

Set the CommandName="Select" for your buttoncolumn.

In the OnSelectedIndexChanged event of the first datagrid
(NOT the OnClick event of the button), use this expression to
retrieve the house_id:

selectedHouseID = DataGrid1.DataKeys(e.Item.ItemIndex)

With this ID, bind your second datagrid.

You can also find a complete template in Web Matrix (use the Master/Detail
Data template).
 
K

Karl Napp

selectedHouseID = DataGrid1.DataKeys(e.Item.ItemIndex)

I do get a compiler error when trying to access
"e.Item"

This seems to be due to the follwing wire-up:

this.Houses.SelectedIndexChanged += new
System.EventHandler(this.Houses_SelectedIndexChanged);

But when I cange it to

this.Houses.SelectedIndexChanged += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.Houses_SelectedIn
dexChanged);

This doesn't help any further...
You can also find a complete template in Web Matrix (use the Master/Detail
Data template).

Is it possible to download this for VS.Net, too?


Thank you
KN
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top