"parent / child" datagrids

Discussion in 'ASP .Net Datagrid Control' started by Danny Sikora, Feb 11, 2005.

  1. Danny Sikora

    Danny Sikora Guest

    Hello,

    I have a datagrid on a .aspx page, and another datagrid on a .ascx page. My
    goal is to populate the "child" datagrid (the one from the control) depending
    on the selected index of the parent datagrid. The child control gets the
    DataKeyField of the selected index of the datagrid from the parent page to
    use to populate it's datagrid.

    So, when I call a sort, edit, or whatever from the child datagrid, it fires
    a postback to the parent page, and so I have to reload the control in the
    page_load area of of the parent page....fine so far.

    My problem comes when I select a new item from the parent datagrid. The
    page posts back, and then it reloads my child control, but it still has the
    ID from the previously selected Item because it reloads the control before it
    fires the DataGrid.OnSelectCommand function.

    I tried to clear the placeholder that I load the control into, and reload
    the control. This sort-of works...at this point there is 2 controls (one
    loaded from page_load, and one from the selected index changed), but only one
    is visible.

    Is there a way to actually DELETE or UNLOAD a control from the page or
    placeholder, and actually reload it, as opposed to the placeHolder.Clear()
    function.

    Thanks,

    Danny
     
    Danny Sikora, Feb 11, 2005
    #1
    1. Advertising

  2. Danny Sikora

    Roy Guest

    Hey Danny, thanks for replying in my thread. I had actually already
    given the always posting back a try, but it's...not doing what it
    should. Long story. I'll figure it out sooner or later. Though if you
    get the chance, take a look at this thread:

    http://groups-beta.google.com/group...r=recent&&_doneTitle=Back&&d#13eca62f5ce552c7

    It's my latest little error, and I strongly suspect you may have some
    insight...

    But enough about me, on to your error. Reading your post above makes me
    realize once again how many different ways there are to code the same
    thing. :) We're coming at it from completely different angles. For
    instance, I don't use the datakeyfield or selected index properties
    anywhere in my code. Here's what I do, in my .aspx page I have my
    template column containing my nested datagrid/user control. NOTE my
    setting of variables below. I'm "linking" the two thusly.

    <asp:TemplateColumn><ItemTemplate>
    <tr><td colspan="9">
    <UC_Grid:Nested id="FVDGrid" x=<%# container.dataitem("vown")%> y=<%#
    container.dataitem("van_no")%> runat="server" />
    </td></tr>
    </ItemTemplate></asp:TemplateColumn>

    Then in my .ascx page I declare x and y and then use them to set my
    sqlcommand's variables which gets passed to a stored proc. Observe:

    With FVDCommand
    ..CommandType = CommandType.StoredProcedure
    ..Parameters.Add (New SqlParameter("@x", SqlDbType.nvarchar,50)).Value =
    x
    ..Parameters.Add (New SqlParameter("@y", SqlDbType.nvarchar,50)).Value =
    y
    End With

    Simple. Easy. No fuss.

    Good luck!
     
    Roy, Feb 12, 2005
    #2
    1. Advertising

  3. Danny Sikora

    Roy Guest

    Hey Danny, thanks for replying in my thread. I had actually already
    given the always posting back a try, but it's...not doing what it
    should. Long story. I'll figure it out sooner or later. Though if you
    get the chance, take a look at this thread:

    http://groups-beta.google.com/group...r=recent&&_doneTitle=Back&&d#13eca62f5ce552c7

    It's my latest little error, and I strongly suspect you may have some
    insight...

    But enough about me, on to your error. Reading your post above makes me
    realize once again how many different ways there are to code the same
    thing. :) We're coming at it from completely different angles. For
    instance, I don't use the datakeyfield or selected index properties
    anywhere in my code. Here's what I do, in my .aspx page I have my
    template column containing my nested datagrid/user control. NOTE my
    setting of variables below. I'm "linking" the two thusly.

    <asp:TemplateColumn><ItemTemplate>
    <tr><td colspan="9">
    <UC_Grid:Nested id="FVDGrid" x=<%# container.dataitem("vown")%> y=<%#
    container.dataitem("van_no")%> runat="server" />
    </td></tr>
    </ItemTemplate></asp:TemplateColumn>

    Then in my .ascx page I declare x and y and then use them to set my
    sqlcommand's variables which gets passed to a stored proc. Observe:

    With FVDCommand
    ..CommandType = CommandType.StoredProcedure
    ..Parameters.Add (New SqlParameter("@x", SqlDbType.nvarchar,50)).Value =
    x
    ..Parameters.Add (New SqlParameter("@y", SqlDbType.nvarchar,50)).Value =
    y
    End With

    Simple. Easy. No fuss.

    Good luck!
     
    Roy, Feb 12, 2005
    #3
  4. Danny Sikora

    Roy Guest

    Hey Danny, thanks for replying in my thread. I had actually already
    given the always posting back a try, but it's...not doing what it
    should. Long story. I'll figure it out sooner or later. Though if you
    get the chance, take a look at this thread:

    http://groups-beta.google.com/group...r=recent&&_doneTitle=Back&&d#13eca62f5ce552c7

    It's my latest little error, and I strongly suspect you may have some
    insight...

    But enough about me, on to your error. Reading your post above makes me
    realize once again how many different ways there are to code the same
    thing. :) We're coming at it from completely different angles. For
    instance, I don't use the datakeyfield or selected index properties
    anywhere in my code. Here's what I do, in my .aspx page I have my
    template column containing my nested datagrid/user control. NOTE my
    setting of variables below. I'm "linking" the two thusly.

    <asp:TemplateColumn><ItemTemplate>
    <tr><td colspan="9">
    <UC_Grid:Nested id="FVDGrid" x=<%# container.dataitem("vown")%> y=<%#
    container.dataitem("van_no")%> runat="server" />
    </td></tr>
    </ItemTemplate></asp:TemplateColumn>

    Then in my .ascx page I declare x and y and then use them to set my
    sqlcommand's variables which gets passed to a stored proc. Observe:

    With FVDCommand
    ..CommandType = CommandType.StoredProcedure
    ..Parameters.Add (New SqlParameter("@x", SqlDbType.nvarchar,50)).Value =
    x
    ..Parameters.Add (New SqlParameter("@y", SqlDbType.nvarchar,50)).Value =
    y
    End With

    Simple. Easy. No fuss.

    Good luck!
     
    Roy, Feb 12, 2005
    #4
  5. Danny Sikora

    Roy Guest

    I have no clue why there are two messages from me with exclamation
    marks... darn google groups...

    Hey, when we are both done with our projects, care to swap code? I'm
    planning on learning C# in a few months anyhow, so the code would be a
    nice introduction.
     
    Roy, Feb 12, 2005
    #5
  6. Danny Sikora

    Danny Sikora Guest

    Sorry Can't - I'd get fired.

    "Roy" wrote:

    > I have no clue why there are two messages from me with exclamation
    > marks... darn google groups...
    >
    > Hey, when we are both done with our projects, care to swap code? I'm
    > planning on learning C# in a few months anyhow, so the code would be a
    > nice introduction.
    >
    >
     
    Danny Sikora, Feb 14, 2005
    #6
  7. Danny Sikora

    Roy Guest

    How so?

    A million folks the world over must've cranked out a million identical
    projects. I work for as a contractor for the US Military and routinely
    trade (and post) code online. It's all good. Unless your employer has
    applied for a patent (which would be quite impossible in the case of
    nested datagrids), it's your code to do with as you wish.
     
    Roy, Feb 16, 2005
    #7
    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. dbuchanan
    Replies:
    3
    Views:
    2,893
    dbuchanan
    Dec 16, 2005
  2. mark
    Replies:
    1
    Views:
    586
  3. davout
    Replies:
    0
    Views:
    571
    davout
    Apr 18, 2004
  4. Crash

    Parent Child data in multiple datagrids

    Crash, Aug 11, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    182
    Crash
    Aug 11, 2004
  5. Replies:
    0
    Views:
    221
Loading...

Share This Page