DropDownTree - DropDownTree in RadGrid

Edit the grid entries to be able to adjust the supplier name with the help of the RadDropDownTree. The control shows the suppliers' hierarchy.
Supplier NameTerritoryTerritoryID Edit
123
Page size:
 49 items in 3 pages
  • Fuller
    • Davolio
    • Leverling
    • Peacock
    • Buchanan
      • Suyama
      • King
      • Dodsworth
    • Callahan
 
Fuller Bedford01730
Fuller Georgetow01833
Fuller Boston02116
Fuller Cambridge02139
Fuller Braintree02184
Buchanan Providence02903
Dodsworth Hollis03049
Dodsworth Portsmouth03801
Davolio Wilton06897
Buchanan Morristown07960
Buchanan Edison08837
Buchanan New York10019
Buchanan New York10038
Buchanan Mellvile11747
Buchanan Fairport14450
Callahan Philadelphia19428
Davolio Neward19713
Peacock Rockville20852
Peacock Greensboro27403
Isolate this demo as a stand-alone application
  • About this demo
  • C#
  • VB
There are two options to pre-select a value in the RadDropDownTree when it is nested in the RadGrid EditTemplate.
If you populate RadDropDownTree with data using ASP.NET 2.0 or 3.5 DataSource types, you can simply set the SelectedValue or SelectedText in the following way:
  • SelectedValue='<%#Bind("EmployeeID") %>'
  • SelectedText='<%#Bind("LastName") %>'
  • DefaultCS.aspx
  • DefaultCS.aspx.cs
<%@ Page AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DropDownTree.Examples.ApplicationScenarios.DropDownTreeInGrid.DefaultCS"Language="c#"  %>

<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
    <title>Telerik ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
    <telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid2">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid2" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <qsf:MessageBox ID="InformationBox1" runat="server" Type="Info" Icon="Info">
        Edit the grid entries to be able to adjust the supplier name with the help of the RadDropDownTree. 
            The control shows the suppliers' hierarchy.
    </qsf:MessageBox>
    <div class="demo-container">
        <telerik:RadGrid RenderMode="Lightweight" ID="RadGrid2" GridLines="None" AutoGenerateColumns="false" PageSize="20"
            AllowPaging="true" AllowSorting="true" runat="server" OnItemDataBound="RadGrid2_ItemDataBound"
            DataSourceID="SqlDataSource1" AllowAutomaticUpdates="true"
            ShowStatusBar="true" OnItemCreated="RadGrid2_ItemCreated">
            <MasterTableView ShowFooter="false" TableLayout="Fixed" EditMode="InPlace" CommandItemDisplay="TopAndBottom" CommandItemSettings-ShowAddNewRecordButton="false">
                <SortExpressions>
                    <telerik:GridSortExpression FieldName="TerritoryID" SortOrder="Ascending" />
                </SortExpressions>
                <Columns>
                    <telerik:GridTemplateColumn HeaderText="Supplier Name">
                        <ItemTemplate>
                            <%#DataBinder.Eval(Container.DataItem, "LastName")%>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <telerik:RadDropDownTree RenderMode="Lightweight" runat="server" ID="RadDropDownTreeTest" DataTextField="LastName" DataFieldParentID="ReportsTo"
                                DataFieldID="EmployeeID" OnDataBound="RadDropDownTreeTest_DataBound"
                                DataValueField="EmployeeID" DataSourceID="SqlDataSource2" SelectedValue='<%#Bind("EmployeeID") %>'>
                                <DropDownSettings OpenDropDownOnLoad="true" CloseDropDownOnSelection="true" />
                            </telerik:RadDropDownTree>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="TerritoryDescription" HeaderText="Territory" />
                    <telerik:GridBoundColumn DataField="TerritoryID" HeaderText="TerritoryID" />
                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn"
                        HeaderText="Edit" HeaderStyle-Width="100px" UpdateText="Update">
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
        SelectCommand="SELECT EmployeeID, ReportsTo, LastName FROM [Employees]"></asp:SqlDataSource>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
        SelectCommand="SELECT mediator.[EmployeeID], mediator.[TerritoryID], territories.[TerritoryDescription], empl.[LastName]
                            FROM [EmployeeTerritories] AS mediator
                            INNER JOIN Employees AS empl
                            ON mediator.EmployeeID = empl.EmployeeID
                            INNER JOIN Territories AS territories
                            ON mediator.TerritoryID = territories.TerritoryID"
        UpdateCommand="UPDATE EmployeeTerritories
                       SET  EmployeeTerritories.EmployeeID = @EmployeeID
                       WHERE EmployeeTerritories.TerritoryID = @TerritoryID">

        <UpdateParameters>
            <asp:Parameter Name="EmployeeID" Type="Int32" />
            <asp:Parameter Name="TerritoryID" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    </form>
</body>
</html>

Support & Learning Resources

Find Assistance

Help Us Improve

Was this example helpful?