Datagrid within a Datagrid, treeview style....

R

Roy

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!
-R
 
R

Roy

My company does not have VS .net, therefore, I can't import 3rd party
treeview web controls. I'm doing everything by hand... :/
 
R

Roy

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
system.eventargs)
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. :)

**********************************************************8

<%@ 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()
dgMaster.DataBind()
End Sub

Function GetPOE() As DataTable
Dim ds As New DataSet()
Dim conn As New
SqlConnection("server=localhost;uid=itv;pwd=itv_$ql!;database=maersk_test")
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
SqlConnection("server=localhost;uid=itv;pwd=itv_$ql!;database=maersk_test")
Dim strSQL As String
Dim ds As New DataSet()

strSQL = "SELECT IsNull(firstvd.ocean_carrier_cd, ''),
IsNull(firstvd.carrier_booking_nr, ''),IsNull(firstvd.equipment, '') "
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

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:datagrid id="dgMaster" runat="server"
autogeneratecolumns="False">
<Columns>
<asp:BoundColumn DataField="voydoc"
HeaderText="VoyDoc"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Column2">
<ItemTemplate>
<asp:DataGrid runat="server" id="dgDetails"
AutoGenerateColumns="False" DataSource=<%#
GetDetails(container.dataitem("voydoc"),container.dataitem("poe"))%> >
<Columns>
<asp:BoundColumn
DataField="ocean_carrier_cd" HeaderText="Carrier"></asp:BoundColumn>
<asp:BoundColumn
DataField="carrier_booking_nr" HeaderText="Booking
#"></asp:BoundColumn>
<asp:BoundColumn DataField="Equipment"
HeaderText="Equipment"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</form>
</body>
</html>
 
R

Roy

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?
 
K

Ken Cox [Microsoft MVP]

P.s : If this post was helpful, please click 'Yes' on the top of this post
to close this thread. Thanks

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 msnews.microsoft.com's groups.
 
R

Roy

Aye, no "Yes" appears using Outlook's newsreader or google groups site.
Anyone else have helpful info on nested, editable grids?
 
R

R. Thomas, aka Xtreme.Net

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
need...
If you need everything to be done, I suggest you go for 3rd party controls
R. Thomas
 
R

Roy

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?
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top