6 Answers, 1 is accepted
0
Hello Felice,
In order to retrieve a specific data field value from an item you should first include that data field in the ClientDataKeyNames collection of the RadTreeList if your requirement is to retrieve the value on client-side. Using the button element you can then get reference to the corresponding TR element of the item and using the id of the TR element, to find the data item. Once you have reference to the data item you can use the get_dataKeyValue() method for retrieving the value:
And the code-behind:
The same principal should be used with a server-side requirement, where you can handle the OnItemCommand event of the RadTreeList and use the GetDataKeyValue method of the TreeListDataItem:
Hope this helps.
Regards,
Konstantin Dikov
Telerik
In order to retrieve a specific data field value from an item you should first include that data field in the ClientDataKeyNames collection of the RadTreeList if your requirement is to retrieve the value on client-side. Using the button element you can then get reference to the corresponding TR element of the item and using the id of the TR element, to find the data item. Once you have reference to the data item you can use the get_dataKeyValue() method for retrieving the value:
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function buttonClick(sender, args) {
var buttonElement = sender.get_element();
var treeList = $find("<%=RadTreeList2.ClientID%>");
var itemElement = treeList._getFirstParentByTagName(buttonElement, "TR");
treeList.get_dataItems();
var dataItem = $find(itemElement.id);
var employeeID = dataItem.get_dataKeyValue("EmployeeID");
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel2"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
>
<
telerik:RadTreeList
runat
=
"server"
ID
=
"RadTreeList2"
AllowPaging
=
"true"
PageSize
=
"3"
ClientDataKeyNames
=
"EmployeeID"
DataKeyNames
=
"EmployeeID"
ParentDataKeyNames
=
"ReportsTo"
OnNeedDataSource
=
"RadTreeList2_NeedDataSource"
>
<
Columns
>
<
telerik:TreeListTemplateColumn
>
<
ItemTemplate
>
<
telerik:RadButton
runat
=
"server"
ID
=
"RadButton1"
AutoPostBack
=
"false"
Text
=
"Test click"
OnClientClicked
=
"buttonClick"
></
telerik:RadButton
>
</
ItemTemplate
>
</
telerik:TreeListTemplateColumn
>
</
Columns
>
</
telerik:RadTreeList
>
</
telerik:RadAjaxPanel
>
And the code-behind:
public
DataTable GetDataTable()
{
String ConnString = ConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(ConnString);
SqlDataAdapter adapter =
new
SqlDataAdapter();
adapter.SelectCommand =
new
SqlCommand(
"SELECT EmployeeID, LastName, FirstName, Title, TitleOfCourtesy, ReportsTo FROM Employees"
, conn);
DataTable myDataTable =
new
DataTable();
conn.Open();
try
{
adapter.Fill(myDataTable);
}
finally
{
conn.Close();
}
return
myDataTable;
}
protected
void
RadTreeList2_NeedDataSource(
object
source, TreeListNeedDataSourceEventArgs e)
{
RadTreeList2.DataSource = GetDataTable();
}
The same principal should be used with a server-side requirement, where you can handle the OnItemCommand event of the RadTreeList and use the GetDataKeyValue method of the TreeListDataItem:
protected
void
RadTreeList2_ItemCommand(
object
sender, TreeListCommandEventArgs e)
{
if
(e.CommandName ==
"customCommandName"
)
{
if
(e.Item
is
TreeListDataItem)
{
TreeListDataItem item = e.Item
as
TreeListDataItem;
string
id = item.GetDataKeyValue(
"EmployeeID"
).ToString();
}
}
}
Hope this helps.
Regards,
Konstantin Dikov
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

Felice
Top achievements
Rank 1
answered on 29 Dec 2014, 02:57 PM
Hello Konstantin,
thanks a lot for the snippet. Looks like I have a little problem here.....the property panel of the radTreeList is completely empty as you can see from the attached pic.
I also tried to delete the control and make a new one but still the same.
How can I get to the events of the treeList? Should I write them in the xml file? Is this a bug?
Thanks,
Felice
thanks a lot for the snippet. Looks like I have a little problem here.....the property panel of the radTreeList is completely empty as you can see from the attached pic.
I also tried to delete the control and make a new one but still the same.
How can I get to the events of the treeList? Should I write them in the xml file? Is this a bug?
Thanks,
Felice
0
Hello Felice,
Can you please share what version of the controls you are using, so we can test the same version on our end.
As for attaching the event handler, you should use either the markup of your page or the code-behind:
On a side note, please take a look at the following help articles, that should help you in the beginning:
Best Regards,
Konstantin Dikov
Telerik
Can you please share what version of the controls you are using, so we can test the same version on our end.
As for attaching the event handler, you should use either the markup of your page or the code-behind:
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadTreeList1.NeedDataSource += RadTreeList1_NeedDataSource;
}
void
RadTreeList1_NeedDataSource(
object
sender, TreeListNeedDataSourceEventArgs e)
{
//
}
On a side note, please take a look at the following help articles, that should help you in the beginning:
- RadTreeList Design Time
- RadTreeList Server-Side API (especially section Server-side Events)
Best Regards,
Konstantin Dikov
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

Felice
Top achievements
Rank 1
answered on 01 Jan 2015, 11:28 AM
Hi Konstantin,
I am using Q3 2014.
Thanks,
Felice
I am using Q3 2014.
Thanks,
Felice
0

Felice
Top achievements
Rank 1
answered on 01 Jan 2015, 11:29 AM
I am using Q3 2014
Thanks
Thanks
0
Hello Felice,
I have tested the RadTreeList control in a simple project and the Properties window is displaying all the properties as expected.
Can you please test with other controls and see if their properties will be visible in the Properties window. Also, please try to create a new project and see if the same issue will be observed.
I am looking forward to your reply with the results.
Regards,
Konstantin Dikov
Telerik
I have tested the RadTreeList control in a simple project and the Properties window is displaying all the properties as expected.
Can you please test with other controls and see if their properties will be visible in the Properties window. Also, please try to create a new project and see if the same issue will be observed.
I am looking forward to your reply with the results.
Regards,
Konstantin Dikov
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.