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

How to get value from DataBinder.Eval() in Treelist

1 Answer 391 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Xuan Truong
Top achievements
Rank 1
Xuan Truong asked on 12 Nov 2012, 06:36 AM
I have a Treelist with imagebutton inside and Onclientclick . I want DataBinder.Eval(...) return value(e.g : 3), but alert(y) return : "<%#DataBinder.Eval(Container.DataItem,"UserName")%>" instead of "3". Please help me. Thanks
Code :

<telerik:RadTreeList runat="server" ID="RadTreeListUser" DataKeyNames="UserLevelPath" ParentDataKeyNames="ParentUserLevelPath" OnNeedDataSource="RadTreeListUser_NeedDataSource">

<Columns>

  <telerik:TreeListBoundColumn DataField="UserName" HeaderText="User Name" UniqueName="UserName">
  </
telerik:TreeListBoundColumn>


  <
telerik:TreeListTemplateColumn UniqueName="EditItem" MinWidth="10px">

    <ItemTemplate>

      <asp:imagebutton id="ImageButtonEditItem" imageurl="../up.png" runat="server" onclientclick="javascript : var y = '<%#DataBinder.Eval(Container.DataItem,"UserName")%>'; alert(y) ; return false;">
      </
asp:imagebutton>

    </ItemTemplate>

  </telerik:TreeListTemplateColumn>
</
Columns>
</
telerik:RadTreeList>

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 12 Nov 2012, 09:23 AM
Hi,

You can pass the column value in ItemDataBound event as shown below.
C#:
protected void RadTreeList1_ItemDataBound(object sender, Telerik.Web.UI.TreeListItemDataBoundEventArgs e)
{
    if (e.Item is TreeListDataItem)
    {
        TreeListDataItem item = (TreeListDataItem)e.Item;
        string value = item["UserName"].Text;
        ImageButton img = (ImageButton)item.FindControl("ImageButtonEditItem");
        img.Attributes.Add("onclick", "Click('" + value +  "');");
    }
}
JS:
<script type="text/javascript">
function Click(value)
{
  alert(value);
}
</script>

Thanks,
Shinu.
Tags
TreeList
Asked by
Xuan Truong
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or