Unable to bind TreeList

2 posts, 0 answers
  1. Sandeep
    Sandeep avatar
    22 posts
    Member since:
    Apr 2013

    Posted 15 May 2013 Link to this post

    Hi All,

    I am unable to bind treelist  , i am using DataKeyNames and ParentDataKeyName are in different columns. could you please help me on this.

    Regards,
    Sandeep Kumar
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 15 May 2013 Link to this post

    Hi Sandeep,

    Try the following code to bind treelist.

    ASPX:
     <%-- simple binding--%>
     <telerik:RadTreeList runat="server" ID="RadTreeList1" AllowPaging="true" PageSize="3" DataKeyNames="EmployeeID"  ParentDataKeyNames="ReportsTo">
     </telerik:RadTreeList>
     
    <br /><br />
     <%--  Advanced binding--%>
      <telerik:RadTreeList runat="server" ID="RadTreeList2" AllowPaging="true" PageSize="3" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo" OnNeedDataSource="RadTreeList2_NeedDataSource">
      </telerik:RadTreeList>

    C#:
    protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              RadTreeList1.DataSource = GetDataTable(); //simple binding
              RadTreeList1.DataBind();
          }
      }
    public DataTable GetDataTable()
      {
          String ConnString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].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(); //Advance binding
      }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top