Neby question on Selecting a node

3 posts, 0 answers
  1. Chris
    Chris avatar
    28 posts
    Member since:
    Jun 2012

    Posted 11 Jun 2013 Link to this post

    Hi,

    I'm new to using these controls so please forgive my ignorance!  I am using the RadTreeList to display a list of events and some attributes of those events (start date etc).  When the user selects a node in the tree I want to call a server side function to populate another list of the users on that event but I can't seem to work out how that is done.  

    I have looked at the selection examples but I don't want a 'check box' which is what the server side selection uses - I just want to click a row in the tree and call a server side function to populate a list box.  I have implemented the client side OnItemSelected but I'm sure that there must be an event server side that is called when the user clicks on a node...
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Jun 2013 Link to this post

    Hi,

    To achieve the same in server side I have two suggestions.

    1) Use fireCommand.
    ASPX:
    <telerik:RadTreeList runat="server" ID="RadTreeList1" AllowPaging="true"  PageSize="3" DataKeyNames="EmployeeID" AllowMultiItemSelection="true"  ParentDataKeyNames="ReportsTo" onitemcommand="RadTreeList1_ItemCommand">
      <ClientSettings>
        <ClientEvents OnItemClick="OnItemSelected" />
      </ClientSettings>
    </telerik:RadTreeList>
    JS:
    function OnItemSelected(sender, args)
    {
      sender.fireCommand("Select", 0);
    }
    C#:
    protected void RadTreeList1_ItemCommand(object sender, TreeListCommandEventArgs e)
     {
       if (e.CommandName == "Select")
        {
           // your code
        }
     }

    2) Use RadAaxManager.
    ASPX:
    <telerik:RadTreeList runat="server" ID="RadTreeList1">
      <ClientSettings>
        <ClientEvents OnItemClick="OnItemSelected" />
      </ClientSettings>
    </telerik:RadTreeList>
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" onajaxrequest="RadAjaxManager1_AjaxRequest"></telerik:RadAjaxManager>

    JS:
    function OnItemSelected(sender, args)
     {
        $find("<%= RadAjaxManager1.ClientID %>").ajaxRequest();
     }
    C#:
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
     {
          // your code
     }

    Hope this will help you.

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Chris
    Chris avatar
    28 posts
    Member since:
    Jun 2012

    Posted 12 Jun 2013 Link to this post

    Thanks Shinu - I think I am almost there but still having some issues.

    When trying the OnItemSelected approach I only want to postback if a top level item is selected and therefore my asps has the following function

    function rtlSubStages_OnItemSelected(sender, eventArgs)
    {
    var item = eventArgs.get_item();
    var hierarchicalIndex = eventArgs.get_item().get_hierarchicalIndex();

    if (hierarchicalIndex.NestedLevel == 0)
    {
    sender.fireCommand("Select", 0);
    }
    }

    ...and then in my code behind 

    protected void rtlSubStages_ItemCommand(object sender, TreeListCommandEventArgs e)
    {
    if (e.CommandName == "Select")
    {
    // OK which if any event stage detail record has been selected
    string data = rtlSubStages.SelectedItems[0]["ID"].Text;
    int id = int.Parse(data);

    DisplayPersonnel(id);
    }
    }

    The problem is that if |I select item 'A' the personnel are displayed correctly however if I then click item 'B@ I see the screen flicker as the postback occurs and the personnel list is refreshed however item B is highlighted and then immediately item 'A' is highlighted again.  Looks as though the postback is losing the selected item but I'm not clearing anything in my page_load event.

    When using the Ajax approach I have an additional problem in that my Ajax callback handler looks like 

    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
    {
    // OK which if any event stage detail record has been selected
    string data = rtlSubStages.SelectedItems[0]["ID"].Text;
    int id = int.Parse(data);
    DisplayPersonnel(id);
    }

    ...but when I step through this in debug the selected items collection is empty suggesting that the item has not been selected at the point of the ajax callback or has been cleared somehow.  Please any thoughts as this is really causing me problems now!

    In case it is relevant, the RadTreeList is already within an UpdatePanel


Back to Top