TreeView in ComboBox - Selected Value

5 posts, 0 answers
  1. Bader
    Bader avatar
    215 posts
    Member since:
    Aug 2008

    Posted 17 Nov 2011 Link to this post

    Hi,

    I want to put the Radcombobox (Demo: http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx?product=combobox) within formview control. Thats mean, I need to display the selected value on RadComboBox using c# code (For example, Asia). I tried to do that, but it is not working.

    Can you please explain to me how can I do that?

    Regards,
    Bader
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Nov 2011 Link to this post

    Hello Bader,

    Try the following code.
    C#:
    protected void RadTreeView1_NodeClick(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
      {
          FormViewRow row = FormView1.Row;
          RadComboBox rbx = (RadComboBox)row.FindControl("RadComboBox1");
          RadTreeView tree = sender as RadTreeView;
          string s = tree.SelectedNode.Text;
          rbx.EmptyMessage = s;
      }

    -Shinu.
  3. Bader
    Bader avatar
    215 posts
    Member since:
    Aug 2008

    Posted 19 Nov 2011 Link to this post

    Hi,

    Thank you for your reply, Maybe I didn't explain my question clearly.
    I need to set the selected value using the Page_Load and not using the NodeClick event.
    So please, can you explain to me how to access the radtreeview which is placed within the radcombobox and how to set a selected value which is retrieved from the database (In both radcombobox and radtreeview)?

    Regards,
    Bader
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Nov 2011 Link to this post

    Hello,

    You can try the following code snippet.

    JS:
    <script type="text/javascript">
      function OnClientNodeClicked(sender, args)
       {
          var txt = args.get_node().get_text();
          var HiddenField = document.getElementById("HiddenField1");
          HiddenField.value = txt;
          $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
       }
    </script>

    CS:
    protected void Page_Load(object sender, EventArgs e)
      {
         FormViewRow row = FormView1.Row;
         RadComboBox rbx = (RadComboBox)row.FindControl("RadComboBox1");
         rbx.SelectedValue = HiddenField1.Value;
      }
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
      {
            
      }
    Note: Add one RadAjaxManager in ASPX.

    Thanks,
    Shinu.
  5. Bader
    Bader avatar
    215 posts
    Member since:
    Aug 2008

    Posted 21 Nov 2011 Link to this post

    Hello,

    Thank you for your reply,

    I have two problems regarding TreeView in ComboBox:
    1) I set all code related to TreeView in ComboBox (based on http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/treeviewcombobox/defaultcs.aspx?product=combobox) in a user control as bellow. I noticed that TreeView in ComboBox is not working well within Ajax components. I'm loading this usercontrol in a page which uses Ajax components, which are very important and I can't remove them, but that components makes "TreeView in ComboBox" not working (I got an error message - attached). Please, let me know how to solve that problem.

    2) In my case, how to display the selected value on RadComboBox using c# code (The value is stored in a session)? I need to set the selected value also in the TreeView which is inside the ComboBox, I mean, If I click on the ComboBox in order to view the TreeView, I need to see the selcted node in the treeview too.

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="ChangeParentUserControl.ascx.cs" Inherits="GuidesNS.Secure_Mng_Guides_MultipleDocs_UserControls_DiffrentDocsPaths_ChangeParentUserControl" %>
     
    <style type="text/css">
         html.rfdButton a.rfdSkinnedButton
         {
             vertical-align: middle;
             margin: 0 0 0 5px;
         }
         div.RadComboBoxDropDown .rcbItem
         {
             margin: 0;
             padding: 0;
         }
    </style>
     
    <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="all" ControlsToSkip="Scrollbars"></telerik:RadFormDecorator>
     
    <asp:HiddenField ID="HiddenField1" runat="server" />
     
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function nodeClicking(sender, args) {
                var trex = $get("<%= HiddenField1.ClientID %>");
                var comboBox = $find("<%= GuideRadComboBox.ClientID %>");
     
                var node = args.get_node()
     
                comboBox.set_text(node.get_text());
                trex.value = node.get_value();
     
                comboBox.trackChanges();
                comboBox.get_items().getItem(0).set_text(node.get_text());
                comboBox.commitChanges();
            }
     
            function StopPropagation(e) {
                if (!e) {
                    e = window.event;
                }
                e.cancelBubble = true;
            }
     
            function OnClientDropDownOpenedHandler(sender, eventArgs) {
                var tree = sender.get_items().getItem(0).findControl("MyRadTreeView1");
                var selectedNode = tree.get_selectedNode();
                if (selectedNode) {
                    selectedNode.scrollIntoView();
                }
            }
        </script>
    </telerik:RadCodeBlock>
     
    <asp:SqlDataSource ID="GuidePowerShellSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:GeneralConnectionString %>"
                       SelectCommand="SELECT * FROM [guidesQA] where ([Type] Like '%Folder%') order by [Type],[Title] "></asp:SqlDataSource>
     
    <asp:Label ID="ParentFolderLabel" runat="server" Text="Parent Folder:"></asp:Label
     
    <telerik:RadComboBox ID="GuideRadComboBox" runat="server" Width="250px" Height="400px"
        ShowToggleImage="True" Style="vertical-align: middle;" OnClientDropDownOpened="OnClientDropDownOpenedHandler"
        EmptyMessage="Choose a parent folder" ExpandAnimation-Type="None" CollapseAnimation-Type="None">
        <ItemTemplate>
            <div id="div1">
                <telerik:RadTreeView ID="MyRadTreeView1" runat="server" DataValueField="SerID" OnClientNodeClicking="nodeClicking"
                    DataSourceID="GuidePowerShellSqlDataSource" DataFieldParentID="ParentID" DataFieldID="SerID" DataTextField="Title" >
                    <DataBindings>
                        <telerik:RadTreeNodeBinding Depth="0" Expanded="true" />
                    </DataBindings>
                </telerik:RadTreeView>
            </div>
        </ItemTemplate>
        <Items>
            <telerik:RadComboBoxItem Text="" Value="" />
        </Items>
    </telerik:RadComboBox>
     
    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
        <script type="text/javascript">
            var div1 = document.getElementById("div1");
            div1.onclick = StopPropagation;
        </script>
    </telerik:RadCodeBlock>
     
    <asp:Button ID="Button1" runat="server" OnClick="Change_Click" Text="Change" />
    <br />
    <asp:Label ID="Label1" runat="server" Style="display: block; color: #3b9400; margin: 7px 0 30px 0; width: 700px; font-weight: bold; font-size: 11px;"></asp:Label>

    The Button1 method stored the selected node value in the DB.

    Please, I need your help,

    Regards,
    Bader
Back to Top