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

3rd nested table

2 Answers 26 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Stavros
Top achievements
Rank 1
Stavros asked on 21 Dec 2008, 04:41 PM

How can we alter this case

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
 
<%@ Register TagPrefix="radG" Namespace="Telerik.WebControls" Assembly="RadGrid.Net2" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Untitled Page</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
        <div>  
            <radG:RadGrid ID="RadGrid1" EnableAJAX="True" DataSourceID="mainTableSource" runat="server" 
                Width="95%" AutoGenerateColumns="False" PageSize="5" AllowSorting="True" Skin="Windows" 
                AllowPaging="True" AllowAutomaticUpdates="True" AllowAutomaticInserts="True" 
                AllowAutomaticDeletes="True" OnInsertCommand="RadGrid1_InsertCommand" ShowStatusBar="true">  
                <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>  
                <MasterTableView DataSourceID="mainTableSource" CommandItemDisplay="Top" DataKeyNames="EmployeeID" 
                    AllowMultiColumnSorting="True" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" 
                    AllowAutomaticInserts="true">  
                    <DetailTables>  
                        <radG:GridTableView DataKeyNames="EmployeeID, OrderID" DataSourceID="nestedTableSource" 
                            Width="100%" runat="server" AllowAutomaticDeletes="true" AllowAutomaticInserts="true" 
                            AllowAutomaticUpdates="true" CommandItemDisplay="Top">  
                            <ParentTableRelation>  
                                <radG:GridRelationFields DetailKeyField="EmployeeID" MasterKeyField="EmployeeID" />  
                            </ParentTableRelation>  
                            <Columns>  
                                <radG:GridBoundColumn SortExpression="OrderID" HeaderText="OrderID" HeaderButtonType="TextButton" 
                                    DataField="OrderID" UniqueName="OrderID" ReadOnly="true">  
                                </radG:GridBoundColumn>  
                                <radG:GridBoundColumn SortExpression="ShipVia" HeaderText="Ship via" HeaderButtonType="TextButton" 
                                    DataField="ShipVia" UniqueName="ShipVia">  
                                </radG:GridBoundColumn>  
                                <radG:GridBoundColumn SortExpression="ShipName" HeaderText="Ship name" HeaderButtonType="TextButton" 
                                    DataField="ShipName" UniqueName="ShipName">  
                                </radG:GridBoundColumn>  
                                <radG:GridBoundColumn SortExpression="ShipCity" HeaderText="Ship city" HeaderButtonType="TextButton" 
                                    DataField="ShipCity" UniqueName="ShipCity">  
                                </radG:GridBoundColumn>  
                                <radG:GridBoundColumn SortExpression="ShipCountry" HeaderText="Ship country" HeaderButtonType="TextButton" 
                                    DataField="ShipCountry" UniqueName="ShipCountry">  
                                </radG:GridBoundColumn>  
                                <radG:GridEditCommandColumn UniqueName="EditCommandColumn" />  
                                <radG:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" />  
                            </Columns>  
                        </radG:GridTableView>  
                    </DetailTables>  
                    <Columns>  
                        <radG:GridBoundColumn SortExpression="FirstName" HeaderText="First name" HeaderButtonType="TextButton" 
                            DataField="FirstName" UniqueName="FirstName">  
                        </radG:GridBoundColumn>  
                        <radG:GridBoundColumn SortExpression="LastName" HeaderText="Last name" HeaderButtonType="TextButton" 
                            DataField="LastName" UniqueName="LastName">  
                        </radG:GridBoundColumn>  
                        <radG:GridBoundColumn SortExpression="Address" HeaderText="Address" HeaderButtonType="TextButton" 
                            DataField="Address" UniqueName="Address">  
                        </radG:GridBoundColumn>  
                        <radG:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton" 
                            DataField="City" UniqueName="City" />  
                        <radG:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton" 
                            DataField="Country" UniqueName="Country">  
                        </radG:GridBoundColumn>  
                        <radG:GridEditCommandColumn UniqueName="EditCommandColumn" />  
                        <radG:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" />  
                    </Columns>  
                </MasterTableView>  
            </radG:RadGrid>  
            <asp:SqlDataSource ID="mainTableSource" SelectCommand="SELECT [EmployeeID], [LastName], [FirstName], [Address], [City], [Country] FROM [Employees]" 
                runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                DeleteCommand="DELETE FROM [Employees] WHERE [EmployeeID] = @original_EmployeeID" 
                InsertCommand="INSERT INTO [Employees] ([LastName], [FirstName], [Address], [City], [Country]) VALUES (@LastName, @FirstName, @Address, @City, @Country)" 
                OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Employees] SET [LastName] = @LastName, [FirstName] = @FirstName, [Address] = @Address, [City] = @City, [Country] = @Country WHERE [EmployeeID] = @original_EmployeeID AND [LastName] = @original_LastName AND [FirstName] = @original_FirstName AND [Address] = @original_Address AND [City] = @original_City AND [Country] = @original_Country">  
                <DeleteParameters>  
                    <asp:Parameter Name="original_EmployeeID" Type="Int32" />  
                </DeleteParameters>  
                <UpdateParameters>  
                    <asp:Parameter Name="LastName" Type="String" />  
                    <asp:Parameter Name="FirstName" Type="String" />  
                    <asp:Parameter Name="Address" Type="String" />  
                    <asp:Parameter Name="City" Type="String" />  
                    <asp:Parameter Name="Country" Type="String" />  
                    <asp:Parameter Name="original_EmployeeID" Type="Int32" />  
                    <asp:Parameter Name="original_LastName" Type="String" />  
                    <asp:Parameter Name="original_FirstName" Type="String" />  
                    <asp:Parameter Name="original_Address" Type="String" />  
                    <asp:Parameter Name="original_City" Type="String" />  
                    <asp:Parameter Name="original_Country" Type="String" />  
                </UpdateParameters>  
                <InsertParameters>  
                    <asp:Parameter Name="LastName" Type="String" />  
                    <asp:Parameter Name="FirstName" Type="String" />  
                    <asp:Parameter Name="Address" Type="String" />  
                    <asp:Parameter Name="City" Type="String" />  
                    <asp:Parameter Name="Country" Type="String" />  
                </InsertParameters>  
            </asp:SqlDataSource>  
            <asp:SqlDataSource ID="nestedTableSource" SelectCommand="SELECT [OrderID],[EmployeeID], [ShipVia], [ShipName], [ShipCity], [ShipCountry] FROM [Orders] WHERE ([EmployeeID] = @EmployeeID)" 
                runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString2 %>" 
                DeleteCommand="DELETE FROM [Orders] WHERE [OrderID] = @original_OrderID" InsertCommand="INSERT INTO [Orders] ([EmployeeID], [ShipVia], [ShipName], [ShipCity], [ShipCountry]) VALUES (@EmployeeID, @ShipVia, @ShipName, @ShipCity, @ShipCountry)" 
                OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Orders] SET [ShipVia] = @ShipVia, [ShipName] = @ShipName, [ShipCity] = @ShipCity, [ShipCountry] = @ShipCountry WHERE [OrderID] = @original_OrderID AND [ShipVia] = @original_ShipVia AND [ShipName] = @original_ShipName AND [ShipCity] = @original_ShipCity AND [ShipCountry] = @original_ShipCountry">  
                <SelectParameters>  
                    <asp:SessionParameter Name="EmployeeID" SessionField="EmployeeID" Type="Int32" Direction="Input" />  
                </SelectParameters>  
                <DeleteParameters>  
                    <asp:Parameter Name="original_OrderID" Type="Int32" />  
                </DeleteParameters>  
                <UpdateParameters>  
                    <asp:Parameter Name="ShipVia" Type="Int32" />  
                    <asp:Parameter Name="ShipName" Type="String" />  
                    <asp:Parameter Name="ShipCity" Type="String" />  
                    <asp:Parameter Name="ShipCountry" Type="String" />  
                    <asp:Parameter Name="original_OrderID" Type="Int32" />  
                    <asp:Parameter Name="original_ShipVia" Type="Int32" />  
                    <asp:Parameter Name="original_ShipName" Type="String" />  
                    <asp:Parameter Name="original_ShipCity" Type="String" />  
                    <asp:Parameter Name="original_ShipCountry" Type="String" />  
                </UpdateParameters>  
                <InsertParameters>  
                    <asp:SessionParameter Name="EmployeeID" SessionField="EmployeeID" Type="Int32" />  
                    <asp:Parameter Name="ShipVia" Type="Int32" />  
                    <asp:Parameter Name="ShipName" Type="String" />  
                    <asp:Parameter Name="ShipCity" Type="String" />  
                    <asp:Parameter Name="ShipCountry" Type="String" />  
                </InsertParameters>  
            </asp:SqlDataSource>  
        </div>  
    </form>  
</body>  
</html>  
 

 

 

..to add one more nested table with DataKeyNames="EmployeeID, OrderID, newColumnID" ?

 

Thank you!

2 Answers, 1 is accepted

Sort by
0
Stavros
Top achievements
Rank 1
answered on 21 Dec 2008, 05:02 PM
I am posting the code here to tell me what I am doing wrong :

http://www.shorttext.com/wgh5im

Thank you for your attention.
0
Stavros
Top achievements
Rank 1
answered on 21 Dec 2008, 05:13 PM
I found the error using this link : http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingneeddatasource.html

I copy from the link :

Every GridRelationFields object should has only one field name for DetailKeyField and MasterKeyField
Tags
Grid
Asked by
Stavros
Top achievements
Rank 1
Answers by
Stavros
Top achievements
Rank 1
Share this question
or