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

Datalist inside RadGrid...?

4 Answers 112 Views
Grid
This is a migrated thread and some comments may be shown as answers.
YMA
Top achievements
Rank 1
YMA asked on 28 Aug 2012, 08:43 PM
I wonder if someone could help me solve this issue:

I need to have a Datalist (for layout purposes etc.) inside a RadGrid in a Parent/Child relationship.

Hi,

For some reason the parent/child link does not quite work for me. In the Northwind database when I click on say OrderID 10248 -it also populates the order details of OrderID 10248 to all the other OrderID's (i.e. 10249, 10250 etc.). What I am doing wrong...?

Thanks in advance!

/J

The sample code is included below:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        <Scripts>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.Core.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQuery.js">
            </asp:ScriptReference>
            <asp:ScriptReference Assembly="Telerik.Web.UI"
                Name="Telerik.Web.UI.Common.jQueryInclude.js">
            </asp:ScriptReference>
        </Scripts>
    </telerik:RadScriptManager>
    <div>
         
        <telerik:RadGrid ID="RadGrid1" runat="server" CellSpacing="0"
            DataSourceID="SqlDataSource1" GridLines="None">
<MasterTableView AutoGenerateColumns="False" DataKeyNames="OrderID"
                DataSourceID="SqlDataSource1">
 
<ParentTableRelation>
                <telerik:GridRelationFields DetailKeyField="OrderID"
                    MasterKeyField="OrderID" />
                    </ParentTableRelation>
    <NestedViewTemplate>
        <asp:DataList ID="DataList1" runat="server" DataKeyField="OrderID"
            DataSourceID="SqlDataSource2">
            <ItemTemplate>
                OrderID:
                <asp:Label ID="OrderIDLabel" runat="server" Text='<%# Eval("OrderID") %>' />
                <br />
                ProductID:
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' />
                <br />
                UnitPrice:
                <asp:Label ID="UnitPriceLabel" runat="server" Text='<%# Eval("UnitPrice") %>' />
                <br />
                Quantity:
                <asp:Label ID="QuantityLabel" runat="server" Text='<%# Eval("Quantity") %>' />
                <br />
                Discount:
                <asp:Label ID="DiscountLabel" runat="server" Text='<%# Eval("Discount") %>' />
                <br />
<br />
            </ItemTemplate>
        </asp:DataList>
    </NestedViewTemplate>
     
    <NestedViewSettings DataSourceID="SqlDataSource2">
        <ParentTableRelation>
            <telerik:GridRelationFields DetailKeyField="OrderID"
                MasterKeyField="OrderID" />
        </ParentTableRelation>
    </NestedViewSettings>
 
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
 
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
 
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
 
    <Columns>
        <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32"
            FilterControlAltText="Filter OrderID column" HeaderText="OrderID"
            ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="CustomerID"
            FilterControlAltText="Filter CustomerID column" HeaderText="CustomerID"
            SortExpression="CustomerID" UniqueName="CustomerID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="EmployeeID" DataType="System.Int32"
            FilterControlAltText="Filter EmployeeID column" HeaderText="EmployeeID"
            SortExpression="EmployeeID" UniqueName="EmployeeID">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="OrderDate" DataType="System.DateTime"
            FilterControlAltText="Filter OrderDate column" HeaderText="OrderDate"
            SortExpression="OrderDate" UniqueName="OrderDate">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="RequiredDate" DataType="System.DateTime"
            FilterControlAltText="Filter RequiredDate column" HeaderText="RequiredDate"
            SortExpression="RequiredDate" UniqueName="RequiredDate">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShippedDate" DataType="System.DateTime"
            FilterControlAltText="Filter ShippedDate column" HeaderText="ShippedDate"
            SortExpression="ShippedDate" UniqueName="ShippedDate">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipVia" DataType="System.Int32"
            FilterControlAltText="Filter ShipVia column" HeaderText="ShipVia"
            SortExpression="ShipVia" UniqueName="ShipVia">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="Freight" DataType="System.Decimal"
            FilterControlAltText="Filter Freight column" HeaderText="Freight"
            SortExpression="Freight" UniqueName="Freight">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipName"
            FilterControlAltText="Filter ShipName column" HeaderText="ShipName"
            SortExpression="ShipName" UniqueName="ShipName">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipAddress"
            FilterControlAltText="Filter ShipAddress column" HeaderText="ShipAddress"
            SortExpression="ShipAddress" UniqueName="ShipAddress">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipCity"
            FilterControlAltText="Filter ShipCity column" HeaderText="ShipCity"
            SortExpression="ShipCity" UniqueName="ShipCity">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipRegion"
            FilterControlAltText="Filter ShipRegion column" HeaderText="ShipRegion"
            SortExpression="ShipRegion" UniqueName="ShipRegion">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipPostalCode"
            FilterControlAltText="Filter ShipPostalCode column" HeaderText="ShipPostalCode"
            SortExpression="ShipPostalCode" UniqueName="ShipPostalCode">
        </telerik:GridBoundColumn>
        <telerik:GridBoundColumn DataField="ShipCountry"
            FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry"
            SortExpression="ShipCountry" UniqueName="ShipCountry">
        </telerik:GridBoundColumn>
    </Columns>
 
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
 
<FilterMenu EnableImageSprites="False"></FilterMenu>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT * FROM [Orders]"></asp:SqlDataSource>
 
        <asp:SqlDataSource ID="SqlDataSource2" runat="server"
            ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT OrderID, ProductID, UnitPrice, Quantity, Discount FROM [Order Details] WHERE (OrderID = @OrderID)">
            <SelectParameters>
                <asp:Parameter Name="OrderID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>



4 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 03 Sep 2012, 08:31 AM
Hello YMA,

I am sending you the modified version of your code please check it out and let me know if it helps you. Looking forward for your reply.

All the best,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
YMA
Top achievements
Rank 1
answered on 04 Sep 2012, 02:23 PM
Hi Radoslav,

Just tried it and it works perfectly thanks!! I spent about three weeks trying to figure out what I was doing wrong in the code. The trick seems to be to (1) have the detail datasource control inside the <NestedViewTemplate>, (2) store the OrderID values at order level in a (hidden) data-bound label, (3) remove the <NestedViewSettings> tag.

Again thanks -much appreciated!

Regards
YMA
0
Bethany
Top achievements
Rank 1
answered on 17 Aug 2015, 02:30 PM

Radoslav,

 The example you sent doesn't seem to work anymore. Can you post the specific code related to finding the DataList control programmatically in vb.net? I just need that one piece and I cannot find it anywhere.

0
Eyup
Telerik team
answered on 19 Aug 2015, 11:50 AM
Hello Bethany,

I've already provided a runnable web site to demonstrate how you can achieve this requirement in your other forum thread:
http://www.telerik.com/forums/how-to-access-datalist-from-inside-a-nestedviewtemplate

I can see that you have also opened a formal support ticket with ID: 962460, which is handled by Viktor. I suggest that we continue this conversation only on one of these threads.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
YMA
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
YMA
Top achievements
Rank 1
Bethany
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or