This is a migrated thread and some comments may be shown as answers.

Find Control in template column client-side

4 Answers 153 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
AnneArents
Top achievements
Rank 1
AnneArents asked on 04 Jul 2014, 02:26 PM
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



4 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 09 Jul 2014, 10:31 AM
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.

 
0
Andy
Top achievements
Rank 1
answered on 26 Jun 2015, 03:51 PM
Is there a solution to this issue?  Maybe you could post the results of the ticket.
0
Andy
Top achievements
Rank 1
answered on 26 Jun 2015, 03:59 PM

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()

0
Eyup
Telerik team
answered on 01 Jul 2015, 07:25 AM
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
Tags
TreeList
Asked by
AnneArents
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Andy
Top achievements
Rank 1
Share this question
or