Get Data from one Grid to another

Discussion in 'ASP .Net Datagrid Control' started by Karl Napp, Oct 31, 2003.

  1. Karl Napp

    Karl Napp Guest

    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
    Karl Napp, Oct 31, 2003
    #1
    1. Advertising

  2. Karl Napp

    Jos Guest

    Karl Napp wrote:
    > 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).

    --

    Jos
    Jos, Nov 1, 2003
    #2
    1. Advertising

  3. Karl Napp

    Karl Napp Guest

    > 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
    Karl Napp, Nov 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VmFzYW50aGEgcGVkZGlyZWRkeQ==?=

    Passing grid data from one page to another

    =?Utf-8?B?VmFzYW50aGEgcGVkZGlyZWRkeQ==?=, Aug 22, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,535
    Grant Merwitz
    Aug 23, 2005
  2. loveNUNO
    Replies:
    2
    Views:
    892
    loveNUNO
    Nov 20, 2003
  3. munther
    Replies:
    2
    Views:
    564
    =?Utf-8?B?SmFtZXMgUGFnZQ==?=
    Sep 12, 2007
  4. Vasantha peddireddy

    Passing grid data from one page to another

    Vasantha peddireddy, Aug 22, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    100
    Elton Wang
    Aug 23, 2005
  5. Robert Cohen
    Replies:
    3
    Views:
    249
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page