Hi Pat,
Thank you for posting in the community!
Based on my understanding, you use datagrid to display Master/Details
datatables. You use an extra column to show the details records.
======================================================
I have writen a sample project for this issue, in it, I use SqlServer's
default datatable "Categories" and "Products" in "Northwind" as datasouce.
Based on my research, I use an extra column to include an invisible
datagrid to show the details table. Html view like this:
<asp:datagrid id="Master" style="Z-INDEX: 101; LEFT: 48px; POSITION:
absolute; TOP: 24px" runat="server"
Width="480px" Height="304px" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="CategoryID"></asp:BoundColumn>
<asp:BoundColumn DataField="CategoryName"></asp:BoundColumn>
<asp:BoundColumn DataField="Description"></asp:BoundColumn>
<asp:ButtonColumn Text="Show Details"
ButtonType="PushButton"></asp:ButtonColumn>
<asp:TemplateColumn Visible="False">
<ItemTemplate>
<asp
ataGrid Runat="server" ID="details"
Visible="False"></asp
ataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Then, when user click the "Show details" button, I en-visible that column
and the details datagrid, code below:
Dim ds As Dataset1
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
getsource()
masterdatabind()
End If
End Sub
Public Sub getsource()
Dim adapter1 As SqlDataAdapter = New SqlDataAdapter("select * from
Products", "server=localhost;database=Northwind;uid=sa;pwd=")
Dim adapter2 As SqlDataAdapter = New SqlDataAdapter("select * from
Categories", "server=localhost;database=Northwind;uid=sa;pwd=")
ds = New Dataset1
adapter2.Fill(ds, "Categories")
adapter1.Fill(ds, "Products")
End Sub
Public Sub masterdatabind()
Master.DataSource = ds.Categories
Master.DataBind()
End Sub
Private Sub Master_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
Master.ItemDataBound
Dim dgi As DataGridItem = e.Item
If dgi.ItemType = ListItemType.Item Or dgi.ItemType =
ListItemType.AlternatingItem Then
Dim c As Control
For Each c In dgi.Cells(4).Controls
If TypeOf (c) Is System.Web.UI.WebControls.DataGrid Then
Dim id As Int32 = Int32.Parse(dgi.Cells(0).Text)
Dim dg As DataGrid = CType(c, DataGrid)
Dim dr As DataRow()
dr = ds.Products.Select("CategoryID=" & id)
dg.DataSource = dr
dg.DataBind()
End If
Next
End If
End Sub
Private Sub Master_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
Master.ItemCommand
If CType(e.CommandSource, Button).Text = "Show Details" Then
Master.Columns(4).Visible = True
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
Dim c As Control
For Each c In dgi.Cells(4).Controls
c.Visible = True
Next
CType(e.CommandSource, Button).Text = "Hide Details"
Else
Master.Columns(4).Visible = False
Dim dgi As DataGridItem = CType(e.Item, DataGridItem)
Dim c As Control
For Each c In dgi.Cells(4).Controls
c.Visible = False
Next
CType(e.CommandSource, Button).Text = "Show Details"
End If
The code works well on my machine
=============================================================
Please apply my suggestion above and let me know if it helps resolve your
problem.
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.