Get Data In Client Events

7 posts, 0 answers
  1. Velma
    Velma avatar
    32 posts
    Member since:
    Jul 2011

    Posted 19 Jul 2011 Link to this post

    (I am using version 2011.1.519.40; I will try to get the Q2 release downloaded if that will allow me to get what I need. I see the new LoadOnDemand functionality in the documentation, which would definitely help us.)

    I have the TreeList loading fine from a datatable.

    I need to do just a few things which I expected were straightforward...

    (1) When an item is selected, I need to get two of the bound data items (one of which displays and one of which doesn't--the one that doesn't is the "DataKeyNames" item). I then need to do server side actions depending on what I determine from those two data items.
             (a) I can't find any way to retrieve those data items (astonishingly to me).
             (b) There doesn't appear to be a server side event for Selected. So, what do you recommend for hitting a server method from a client-side event in this context?

    Can you (I mean, Telerik support) or anyone provide a code snippet which would accomplish this?

    (2) When an item is double-clicked, I need to get "DataKeyNames" item, and depending on what I determine from it, possibly expand the node.
             (a) I can't find any way to retrieve this data item (astonishingly to me).
             (b) There doesn't appear to be a server side event for Double-Click. So, what do you recommend for hitting a server method from a client-side event in this context?

    Can you/anyone provide a code snippet which would accomplish this?

    (3) I don't want to add/edit/delete data directly from the list. Can I add or delete programatically, rather than reloading the whole datatable and requerying? Is there a sample showing something like this?

    Actually, I'm willing/just as happy to do any of this server-side, client-side or server-side, whichever...

    Thanks.

  2. Velma
    Velma avatar
    32 posts
    Member since:
    Jul 2011

    Posted 20 Jul 2011 Link to this post

    I got the Q2 release now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Velma
    Velma avatar
    32 posts
    Member since:
    Jul 2011

    Posted 20 Jul 2011 Link to this post

    With the Q2 release,
    I can now get the data values of the cells in the selected/clicked row in client-side events:

    var item = eventArgs.get_item();
    var treelist = item.get_owner();
    var country = treelist.getCellByColumnUniqueName(item, "CountryName").innerText;

    But I still can't get the key values by anything I've tried.
    var key = item.get_dataKeyValue("DataID");
    returns null
    etc.
    I tried adding a hidden column, but nothing I tried would make a hidden column ("style=display:none" is not supported, width=0 doesn't actually hide it completely...).

  5. Velma
    Velma avatar
    32 posts
    Member since:
    Jul 2011

    Posted 26 Jul 2011 Link to this post

    Since nobody has suggested anything, I continue poking away at this.

    I managed to get the keys on the server side:

    if (RadTreeList1.SelectedItems.Count == 0) return;
    TreeListDataItem current = RadTreeList1.SelectedItems[0];
    string dataKeyValue = current.GetDataKeyValue("DataID").ToString();
    string parentKeyValue = current.ParentItem.GetDataKeyValue("DataID").ToString();

    However, the corresponding methods on the client side return null:

     var treelist = $find("<%= RadTreeList1.ClientID %>");
     var items = treelist.get_selectedItems();
    var item = items[0];
    key = item.get_dataKeyValue("DataID"); -- RETURNS NULL
    var parent = item.get_parentItem();
    key = parent.get_dataKeyValue("DataID"); -- RETURNS NULL

    Anybody know how to get this to work?
  6. Velma
    Velma avatar
    32 posts
    Member since:
    Jul 2011

    Posted 26 Jul 2011 Link to this post

    Alright, I hope this may help someone else who may otherwise be banging their head against the wall also.

    There is another attribute of the RadTreeList call "ClientDataKeyNames". I have no idea why.

    So now I have: DataKeyNames="DataID" ParentDataKeyNames="ParentID" ClientDataKeyNames="DataID"

    And then:

    var treelist = $find("<%= RadTreeList1.ClientID %>");
     var items = treelist.get_selectedItems();
    var item = items[0];
    key = item.get_dataKeyValue("DataID"); -- RETURNS CORRECT VALUE!
    var parent = item.get_parentItem();
    key = parent.get_dataKeyValue("DataID"); -- RETURNS CORRECT VALUE!

    Telerik, perhaps you could extract the useful code samples from this thread and add them to the help. Because none of this is documented.
  7. Steve Napurano
    Steve Napurano avatar
    40 posts
    Member since:
    Aug 2009

    Posted 17 Sep 2011 Link to this post

    i know! This treelist is brutal on dicumentation
    All I want to do is get the selected key and child values on server side

    How did you iterate thru the list and get selected values?

  8. Tsvetina
    Admin
    Tsvetina avatar
    1874 posts

    Posted 19 Sep 2011 Link to this post

    Hi Velma and Steve ,

    First, on the ClientDataKeyNames. This property follows the logic of our other databound controls (like RadGrid). The DataKeyNames property is used for creating such collection on the server. It would not be good for performance to create it on the client by default when it is not needed in many cases. Therefore, a separate property is used to mark which values need to be stored on the client too.

    The need of using the ClientDataKeyNames property is outlined in the get_dataKeyValue() property description, too.
    The treelist documentation is still being built and parts are still missing but main client-side specifics are already described in the Client-side programming section.

    As for server-side iteration over the selected items, Steve, have you tried iterating the SelectedItems collection of the RadTreeList control and then the ChildItems collection of each selected item to access all needed values:
    protected void RadTreeList1_PreRender(object sender, EventArgs e)
    {
        foreach (TreeListDataItem item in RadTreeList1.SelectedItems)
        {
            string keyValue = item.GetDataKeyValue("EmployeeID").ToString();
            Response.Write(keyValue);
            foreach (TreeListDataItem childItem in item.ChildItems)
            {
                string childKeyValue = childItem.GetDataKeyValue("EmployeeID").ToString();
                Response.Write(childKeyValue);
            }
        }
    }


    Best wishes,
    Tsvetina
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017