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

2 posts, 1 answers
  1. Xuan Truong
    Xuan Truong avatar
    11 posts
    Member since:
    Jan 2011

    Posted 12 Nov 2012 Link to this post

    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>

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Nov 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top