Find Control in template column client-side

5 posts, 0 answers
  1. AnneArents
    AnneArents avatar
    14 posts
    Member since:
    Jan 2010

    Posted 04 Jul 2014 Link to this post

    Hi,

    I'm converting a Radgrid to a TreeList (user wants to be able to expand/collapse) and I just discovered that the TreeList doesn't use the DataKeyNames the same way the RadGrid does. (I want to access some properties that are part of the query, but not shown in the TreeList).

    I also discovered that the ClientDataKeyNames does work, so now I'm faced with converting some server-side code to client-side code.
    But I can't get it to work.

    On server-side I had this in the ItemDataBound event: (this was for the RadGrid)

    If (e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("OPLEIDING_GEBIED_NIVEAU") > 0) Then
        CType(dataBoundItem.FindControl("chkIsBeroepsdeel"), CheckBox).Visible = False
    End If

    I've been trying to convert this to client-side code using the ItemCreated event:

    function ItemCreated(sender, eventArgs) {
        var item = eventArgs.get_item();
     
        if (item.get_dataKeyValue("OPLEIDING_GEBIED_NIVEAU") > 0) {
            item.findControl("chkDoorrekenen").style.display = 'none';
        }
    }
    but this gives me an error message: 

    JavaScript runtime error: Object doesn't support property or method 'findControl'

    How can I do this client side?

    Cheers,
    CJ



  2. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 09 Jul 2014 Link to this post

    Hello Cheers,

    I've already replied to your enquiry  in ticket with ID: 837156.
    I suggest that we continue our conversation in the mentioned ticket.

    Regards,
    Eyup
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andy
    Andy avatar
    27 posts
    Member since:
    Nov 2010

    Posted 26 Jun 2015 in reply to Eyup Link to this post

    Is there a solution to this issue?  Maybe you could post the results of the ticket.
  5. Andy
    Andy avatar
    27 posts
    Member since:
    Nov 2010

    Posted 26 Jun 2015 Link to this post

    I figure out a solution.  I could get the value of the underling data with the following

    ((System.Data.DataRowView)(((Telerik.Web.UI.TreeListEditableItem)(item)).DataItem)).Row.ItemArray[10].ToString()

  6. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 01 Jul 2015 Link to this post

    Hi Andy,

    I am sharing the content of the ticket as you've requested:

    Please use OnTreeListCreated handler instead:
    Copy Code
    <ClientSettings>
        <ClientEvents OnTreeListCreated="treeListCreated" />
    </ClientSettings>
    JavaScript:
    Copy Code
    function treeListCreated(sender, args) {
        var items = sender.get_dataItems();
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            var checkBox = $telerik.findElement(item.get_element(), "CheckBox1");
            checkBox.disabled = i % 3 == 0;
        }
    }

    You can also check the following article for server-side accessing:
    http://docs.telerik.com/devtools/aspnet-ajax/controls/treelist/items/accessing-cells-and-items

    In order to get the raw data of the item, you can use this approach:
        protected void RadTreeList1_ItemDataBound(object sender, TreeListItemDataBoundEventArgs e)
        {
            if (e.Item is TreeListDataItem)
            {
                TreeListDataItem item = (TreeListDataItem)e.Item;
                var value = DataBinder.Eval(item.DataItem, "Name");
                RadAjaxManager1.Alert(value.ToString());
            }
        }
    }

    Hope this helps. Please give it a try and let me know if it works for you.

    Regards,
    Eyup
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017