This is a migrated thread and some comments may be shown as answers.

NestedGrid does not display right

3 Answers 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dingen
Top achievements
Rank 1
dingen asked on 21 Jan 2010, 09:28 AM
Hi

I am trying to display the orders related to a certain customer, at the moment i am displaying all orders for every customer?

regards

D

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="nestedviewtemplate.aspx.vb" 
    Inherits="_Default" %> 
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %> 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
</head> 
<body class="BODY"
    <form runat="server" id="mainForm" method="post"
    <telerik:RadScriptManager runat="server" ID="ScriptManager1"
    </telerik:RadScriptManager> 
    <!-- content start --> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
    <telerik:RadGrid ID="RadGrid1"  runat="server" AutoGenerateColumns="true" 
        AllowSorting="True" AllowMultiRowSelection="False" AllowPaging="True" PageSize="5" 
        GridLines="None" ShowGroupPanel="true"
        <PagerStyle Mode="NumericPages"></PagerStyle> 
        <MasterTableView DataKeyNames="customerid" AllowMultiColumnSorting="True"
            <NestedViewTemplate> 
                <telerik:RadGrid runat="server" ID="nestedgrid" OnNeedDataSource="onneeddatasource_nestedgrid" 
                    ShowFooter="true" AllowSorting="true" EnableLinqExpressions="false" OnItemCreated="nested_Created" 
                    OnItemCommand="Onitemcommand_nestedgrid_jahoor"
                    <MasterTableView ShowHeader="true" AutoGenerateColumns="true" AllowPaging="true" 
                        PageSize="7"
                        <Columns> 
                            <telerik:GridEditCommandColumn> 
                            </telerik:GridEditCommandColumn> 
                        </Columns> 
                        <EditFormSettings EditFormType="Template"
                            <FormTemplate> 
                                <asp:ImageButton ID="imgb" runat="server" CommandName="go" /> 
                                <asp:Button ID="btn1" runat="server" CommandName="buttonclicked" /> 
                                <asp:DropDownList ID="ddl1" runat="server"
                                </asp:DropDownList> 
                            </FormTemplate> 
                        </EditFormSettings> 
                    </MasterTableView> 
                </telerik:RadGrid> 
            </NestedViewTemplate> 
           <NestedViewSettings >   
               <ParentTableRelation>  
                   <telerik:GridRelationFields DetailKeyField="CustomerID" MasterKeyField="CustomerID" />  
               </ParentTableRelation>  
           </NestedViewSettings>  
            <Columns> 
            </Columns> 
        </MasterTableView> 
        <ClientSettings AllowDragToGroup="true" /> 
    </telerik:RadGrid> 
    
    <!-- content end --> 
    </form> 
</body> 
 

Imports Telerik.Web.UI 
Imports System 
Imports System.Data 
Imports System.Data.SqlClient 
Imports System.Web.UI.WebControls 
Imports System.Configuration 
Partial Class _Default 
    Inherits System.Web.UI.Page 
 
 
    Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString 
 
    Protected Sub nestedgrid_ItemCreated(ByVal sender As ObjectByVal e As GridItemEventArgs) 
        Dim btn As Button 
        Dim ddl As DropDownList 
        If e.Item.ItemType = GridItemType.EditFormItem And e.Item.IsInEditMode Then 
            Dim edititem As GridEditFormItem = CType(e.Item, GridEditFormItem) 
            ddl = CType(edititem.FindControl("ddl1"), DropDownList) 
            btn = CType(edititem.FindControl("btngo"), Button) 
 
            ddl.DataSource = dsddl() 
            ddl.DataTextField = "ShipName" 
            ddl.DataValueField = "OrderID" 
            ddl.DataBind() 
 
        End If 
    End Sub 
 
 
 
    Public Function myds() As DataSet 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        adapter.SelectCommand = New SqlCommand("SELECT TOP 10 OrderID, ShipName, ShipAddress FROM Orders", conn) 
        Dim myDataSet As DataSet = New DataSet 
 
        conn.Open() 
        Try 
            adapter.Fill(myDataSet, "Orders"
            adapter.SelectCommand = New SqlCommand("SELECT OrderID, Quantity FROM [Order Details]", conn) 
            adapter.Fill(myDataSet, "OrderDetails"
        Finally 
            conn.Close() 
        End Try 
        Return myDataSet 
 
    End Function 
 
 
    Public Function dsddl() As DataSet 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        Dim myDataSet As DataSet = New DataSet 
 
        conn.Open() 
        Try 
 
            adapter.SelectCommand = New SqlCommand("SELECT TOP 10 OrderID, ShipName FROM Orders", conn) 
            adapter.Fill(myDataSet, "OrderDetails"
        Finally 
            conn.Close() 
        End Try 
        Return myDataSet 
 
    End Function 
 
 
    Protected Sub nestedgrid_ItemCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        If e.CommandName = "Go" Then 
            Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
            Dim editItem As GridEditFormItem = DirectCast(item.EditFormItem, GridEditFormItem) 
 
            Dim doptdown As DropDownList = DirectCast(editItem.FindControl("ddl1"), DropDownList) 
            Dim value As String = doptdown.SelectedItem.Text 
            Response.Write(value) 
        End If 
    End Sub 
 
    Public Function GetDataTable(ByVal query As StringAs DataTable 
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        adapter.SelectCommand = New SqlCommand(query, conn) 
        Dim table1 As New DataTable 
        conn.Open() 
        Try 
            adapter.Fill(table1) 
        Finally 
            conn.Close() 
        End Try 
        Return table1 
    End Function 
 
 
 
    Public Sub onneeddatasource_nestedgrid(ByVal source As ObjectByVal e As GridNeedDataSourceEventArgs) 
        Dim grid As RadGrid = DirectCast(source, RadGrid) 
        ' Populate the grid         
        grid.DataSource = GetDataTable("SELECT * FROM orders"
    End Sub 
 
 
    Protected Sub Onitemcommand_nestedgrid_jahoor(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        '  Throw New NotImplementedException() 
   Dim item As GridDataItem 
 
        If e.CommandName = "go" Then 
 
            If e.Item.ItemType = GridItemType.Item Then 
                item = CType(e.Item, GridDataItem) 
 
                Dim ddl As DropDownList = CType(item.EditFormItem.FindControl("ddl1"), DropDownList) 
                'ddlEventStatus = CType(itemEdit.FindControl("ddlEventStatus"), DropDownList) 
 
                Response.Write(ddl.SelectedItem.Text) 
            End If 
 
        End If 
    End Sub 
 
    Protected Sub nested_Created(ByVal sender As ObjectByVal e As GridItemEventArgs) 
 
        Dim ddl As DropDownList 
        If e.Item.ItemType = GridItemType.EditFormItem And e.Item.IsInEditMode Then 
            Dim edititem As GridEditFormItem = CType(e.Item, GridEditFormItem) 
            ddl = CType(edititem.FindControl("ddl1"), DropDownList) 
           
            ddl.DataSource = dsddl() 
            ddl.DataTextField = "ShipName" 
            ddl.DataValueField = "OrderID" 
            ddl.DataBind() 
 
        End If 
    End Sub 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        RadGrid1.DataSource = GetDataTable("Select * from customers"
    End Sub 
End Class 
 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 22 Jan 2010, 08:50 AM
Hi dingen,

Given your scenario, you should not be using the NestViewSettings feature of the grid. You need to employ either a regular hierarchy as demonstrated in the following online example:
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/declarativerelations/defaultcs.aspx

or, if you insist on using the nested view template, then just following the online example below (it is however a bit more difficult to implement than the above one):
http://demos.telerik.com/aspnet-ajax/grid/examples/hierarchy/nestedviewtemplate/defaultcs.aspx

The NestedViewSettings feature of RadGrid (which is a subset of the NestedViewTemplate functionality and is not equivalent to it) represents a different scenario more information about which you can find at the following help topic (the paragraph starting with: "RadGrid gives you the ability to data...."):
http://www.telerik.com/help/aspnet-ajax/grdnestedviewtemplate.html

I hope this helps.

Sincerely yours,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
dingen
Top achievements
Rank 1
answered on 22 Jan 2010, 09:44 AM
Hi Tsetsoslav

I am looking for a master detail solution in which i can insert a new detail. So in this example i want to display all the customers with their orders in the 
Also i would like to use a datatable as a datasource so no sqldatasource or objectdatasource. Do you have any idea how to do this?

thanks

D
0
Tsvetoslav
Telerik team
answered on 27 Jan 2010, 09:53 AM
Hi dingen,

Attached is a small sample demonstrating your scenario. I have used a list of business objects which is preferable over the DataTable approach, however, you can easily customize the sample to work with a DataTable as well.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
dingen
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
dingen
Top achievements
Rank 1
Share this question
or