Master Detail/HierarchichlaGrid in ASP.Net 1.x -
Method -1 :- (In ASPX)
DataSource=’<%# CType(Container.DataItem, DataRowView).CreateChildView(“CustOrders”) %>’
e.g
<asp:DataGrid id=”InnerGrid” runat=”server” AutoGenerateColumns=”False”
DataSource=’<%# CType(Container.DataItem, DataRowView).CreateChildView(“CustOrders”) %>’>
<Columns>
---
</Columns>
Method 2:- (In Code)
<asp:DataGrid id=”Outer Grid” runat=”server” AutoGenerateColumns=”False” DataKeyField=”CustomerID” OnItemDataBound=”BindOrdersGrid”>
Sub BindOrdersGrid(sender As Object, e As DataGridItemEventArgs)
Dim oType As ListItemType = CType(e.Item.ItemType, ListItemType)
If oType = ListItemType.Item Or oType = ListItemType.AlternatingItem Then
Dim oGrid As DataGrid = CType(e.Item.FindControl(“InnerGrid”), DataGrid)
Dim sKey As String = dgr1.DataKeys(e.Item.ItemIndex)
Dim oView, oChildView As DataView
oView = oDataSet.Tables(“Customers”).DefaultView
oView.RowFilter = “CustomerID = ‘“ & sKey.value & “‘“
oChildView = oView(0).CreateChildView(oDataSet.Relations(“CustOrders”))
oGrid.DataSource = oChildView
oGrid.DataBind()
End If
End Sub
Method 3:- (In Code)
<asp:DataGrid id=”Outer Grid” runat=”server” AutoGenerateColumns=”False” DataKeyField=”CustomerID”>
<asp:TemplateColumn HeaderText=”Customer Details”>
<ItemTemplate>
<b><%# Container.DataItem(“CompanyName”) %></b><br />
City: <%# Container.DataItem(“City”) %><br />
Country: <%# Container.DataItem(“Country”) %><br />
CustomerID: “<%# Container.DataItem(“CustomerID”) %>”
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText=”Order History”>
<ItemTemplate>
<asp:DataGrid id=” InnerGrid” runat=”server” AutoGenerateColumns=”False”
DataSource=’<%# GetOrdersGridRows( Container.DataItem(“CustomerID”)) %>’>
</ItemTemplate>
</asp:DataGrid> // Outer Grid
Function GetOrdersGridRows(sRowKey As String) As DataView
Dim oView, oChildView As DataView
oView = oDataSet.Tables(“Customers”).DefaultView
oView.RowFilter = “CustomerID = ‘“ & sRowKey & “‘“
oChildView = oView(0).CreateChildView(oDataSet.Relations(“CustOrders”))
Return oChildView
End Function
Thanks & Regards,
Arun Manglick || Tech Lead
No comments:
Post a Comment