Datagrid within a Datagrid, treeview style....

Discussion in 'ASP .Net Datagrid Control' started by Roy, Jan 13, 2005.

  1. Roy

    Roy Guest

    Hey all,
    As the subject suggests, that's what I'm trying to accomplish.
    I'd trying to design something akin to this:

    ->First_Name | Last_Name | blah1 | blah2 | blah3
    --->X | Y | Z
    --->X | Y | Z
    --->X | Y | Z

    First name and last name combined would be the key for the parent table
    that would be the link to the child table which would display the rows
    of "xyz" information. As an added twist, I'm trying to make the child
    records editable. :) I'm not a newcomer to programming as I've been in
    the industry for a couple years, but this is my first exposure to .NET
    and web development, so I'm still very much a newbie in this arena...

    Anyone have any links or better yet, source code that they could post?
    Thanks much!
    Roy, Jan 13, 2005
    1. Advertisements

  2. Why dont you opt for 3rd pary controls?
    R. Thomas, aka Xtreme.Net, Jan 13, 2005
    1. Advertisements

  3. Roy

    Roy Guest

    My company does not have VS .net, therefore, I can't import 3rd party
    treeview web controls. I'm doing everything by hand... :/
    Roy, Jan 13, 2005
  4. Ken Cox [Microsoft MVP], Jan 13, 2005
  5. Roy

    Roy Guest

    Thanks! Anyone bored and care to troubleshoot this for me? Herein lies
    my problem, my inner datagrid is ... well it seems to be looking at my
    outer datagrid's datasource? How can I get around this? The error is:
    "A field or property with the name 'ocean_carrier_cd' was not found on
    the selected data source." Simple enough, right? Well, the column does
    exist within the database, so something is clearly missing here. On
    closer examination the error specificly points to line 8 below:

    "Line 6: Sub Page_Load(sender as system.object, e as
    Line 7: dgMaster.DataSource = GetPOE()
    Line 8: dgMaster.DataBind()
    Line 9: End Sub"

    ....line 8 is a reference to the outer datagrid. Does anyone have any
    idea how to get the inner datagrid to talk to the database w/o going
    through the outer grid? I'm including my full code listing for
    posterity purposes (and of course so that you gurus could peruse it).
    You'd be surprised how hard it is to find anything online regarding a
    datagrid within a datagrid without using VS.NET. :)


    <%@ Page Language="VB" Debug="true" %>
    <%@ import Namespace="System.Data" %>
    <%@ import Namespace="System.Data.SqlClient" %>
    <script runat="server">

    Sub Page_Load(sender as system.object, e as system.eventargs)
    dgMaster.DataSource = GetPOE()
    End Sub

    Function GetPOE() As DataTable
    Dim ds As New DataSet()
    Dim conn As New
    Dim strSQL As String
    strSQL = "SELECT voydoc, poe FROM LLA ORDER BY voydoc"
    Dim da As New SqlDataAdapter(strSQL, conn)
    da.Fill(ds, "lla")
    Return ds.Tables("lla")
    End Function

    Function GetDetails(ByVal x As Object, ByVal y as Object)
    Dim conn As New
    Dim strSQL As String
    Dim ds As New DataSet()

    strSQL = "SELECT IsNull(firstvd.ocean_carrier_cd, ''),
    IsNull(firstvd.carrier_booking_nr, ''),IsNull(, '') "
    strSQL &= "FROM firstvd INNER JOIN "
    strSQL &= "lla ON firstvd.voydoc + firstvd.poe = lla.voydoc +
    lla.poe "
    strSQL &= "WHERE firstvd.voydoc = '"& x.tostring &"' AND
    firstvd.poe = '"& y.tostring &"'"

    Dim da As New SqlDataAdapter(strSQL, conn)
    da.Fill(ds, "firstvd")
    Return ds.Tables("firstvd")
    End Function

    <form runat="server">
    <asp:datagrid id="dgMaster" runat="server"
    <asp:BoundColumn DataField="voydoc"
    <asp:TemplateColumn HeaderText="Column2">
    <asp:DataGrid runat="server" id="dgDetails"
    AutoGenerateColumns="False" DataSource=<%#
    GetDetails(container.dataitem("voydoc"),container.dataitem("poe"))%> >
    DataField="ocean_carrier_cd" HeaderText="Carrier"></asp:BoundColumn>
    DataField="carrier_booking_nr" HeaderText="Booking
    <asp:BoundColumn DataField="Equipment"
    Roy, Jan 14, 2005
  6. R. Thomas, aka Xtreme.Net, Jan 14, 2005
  7. Roy

    Roy Guest

    While I appreciate the reply RT, the link wasn't particularly helpful.
    It was written in C# (and I must use VB) and unless I'm
    misunderstanding something, it's not anything different from what I
    already have...

    Question: will an inner datagrid *always* pull from the outergrid's
    datasource? My code (by my eyes) seems to be telling the inner grid to
    pull from a separate table, yet that is simply not occuring. Where am I
    going wrong?
    Roy, Jan 14, 2005
  8. P.s : If this post was helpful, please click 'Yes' on the top of this post
    What 'Yes' are you referring to? These are widely distributed Usenet
    messages. You can't count on the user seeing a proprietary interface to
    "close" a thread.

    Your best bet would be to post directly in's groups.
    Ken Cox [Microsoft MVP], Jan 14, 2005
  9. Roy

    Roy Guest

    Aye, no "Yes" appears using Outlook's newsreader or google groups site.
    Anyone else have helpful info on nested, editable grids?
    Roy, Jan 14, 2005
  10. The link that I provided you was in C#, so what? does it take a huge effort
    to convert it to VB?
    That is an article about editable datagrid, which is very near to what you
    If you need everything to be done, I suggest you go for 3rd party controls
    R. Thomas
    R. Thomas, aka Xtreme.Net, Jan 14, 2005
  11. Roy

    Roy Guest

    Again, I appreciate the comment, but (and correct me if I'm wrong) the
    link provides no new information. I seem to be using the exact same
    process that the article describes. My code is clearly in error
    somewhere, but I seem unable to isolate the error. One more time:

    In my code above the inner grid appears to be incapable of pulling data
    from the database itself. It attempts to pull it's data from the outer
    grids datasource. How can I fix this? Does anyone know?
    Roy, Jan 14, 2005
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.