RadTreeView - SPDataSource

7 posts, 0 answers
  1. Eric Mauvais
    Eric Mauvais avatar
    7 posts
    Member since:
    Oct 2003

    Posted 26 Mar 2008 Link to this post

    Hi,

    I am trying to bind a RadTreeView to a SPDataSource.

    The SPDataSource points to a SharePoint List which has the following columns :

    • ID
    • ParentID
    • Title
    My list contains the following items :
    ID  ParentID  Title
    1                    News
    2    1              Politics
    3    1              Sports
    4    1              Events


    Here's the code for the RadTreeView inside my page :

    <rad:RadTreeView ID="RadTreeView1" runat="server"  
      DataSourceID="spdatasource1"  
      DataFieldID="ID"  
      DataFieldParentID="ParentID"  
      DataTextField="Title"
    </rad:RadTreeView> 
     

    But instead of displaying my nodes in the proper hierarchy, they are all on the same level.

    Thanks for your help,

    Eric
  2. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 27 Mar 2008 Link to this post

    Hi Eric Mauvais,

    According to the data in your datasource, the TreeNodes should be displayed like:

     - News
       - Politics
       - Sports
       - Events

    Is this what you get as a result?

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center

  3. Eric Mauvais
    Eric Mauvais avatar
    7 posts
    Member since:
    Oct 2003

    Posted 27 Mar 2008 Link to this post

    No, they are displayed like this :

    - News
    - Politics
    - Sports
    - Events



    They're on the same level.
  4. Nikolay
    Admin
    Nikolay avatar
    3997 posts

    Posted 28 Mar 2008 Link to this post

    Hello Eric Mauvais,

    I can suggest that you convert your SPDataSource to a simple datatable and try to bind the treeview to that table.

    Let us know how this goes.

    Regards,
    Nick
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Sakari Hilama
    Sakari Hilama avatar
    6 posts
    Member since:
    Aug 2007

    Posted 31 Mar 2008 Link to this post

    Hi

    I have been thinking about using SharePoint's spdatasource. At the moment I have a treeview which is generated from SharePoint's document library through using a normal datatable. In that table I collect name, ID and parentID and this way everything works well. There might be something odd with spdatasource way but atleast generating this regular datatable works well.

    Yours sincerely
    Sakari
  6. Eric Mauvais
    Eric Mauvais avatar
    7 posts
    Member since:
    Oct 2003

    Posted 31 Mar 2008 Link to this post

    Hi Nick,

    Instead of using a SPDataSource to fill the TreeView, I used this code instead :

    <%@ Import Namespace="Microsoft.SharePoint" %> 
    <%@ Import Namespace="System.Data" %> 
        <script runat="server"
         protected void Page_Load(object sender, System.EventArgs e) 
         { 
            using (SPWeb webSite = SPContext.Current.Web) 
            { 
                SPList menuList = webSite.Lists["Menu"]; 
                SPQuery query = new SPQuery(); 
                SPListItemCollection items = menuList.GetItems(query); 
                DataSet ds = new DataSet(); 
                DataTable table = new DataTable("TreeView"); 
                DataColumn column; 
                DataRow row; 
                 
                // Create each column, set DataType, ColumnName, and add to DataTable 
                // Column ID 
                column = new DataColumn(); 
                column.ColumnName = "ID"
                column.DataType = System.Type.GetType("System.Int32"); 
                column.ReadOnly = true
                column.Unique = true
                table.Columns.Add(column); 
                // Column ParentID 
                column = new DataColumn(); 
                column.ColumnName = "ParentID"
                column.DataType = System.Type.GetType("System.Int32"); 
                column.ReadOnly = true
                column.Unique = false
                table.Columns.Add(column); 
                // Column Title 
                column = new DataColumn(); 
                column.ColumnName = "Title"
                column.DataType = System.Type.GetType("System.String"); 
                column.ReadOnly = true
                column.Unique = false
                table.Columns.Add(column); 
                 
                ds.Tables.Add(table); 
                 
                foreach (SPListItem item in items) 
                { 
                    row = table.NewRow(); 
                    row["ID"] = item["ID"].ToString(); 
                    if (item["ParentID"].ToString() == "0"
                    { 
                        row["ParentID"] = System.DBNull.Value; 
                    } 
                    else 
                    { 
                        row["ParentID"] = item["ParentID"].ToString(); 
                    } 
                    row["Title"] = item["Title"].ToString(); 
                    table.Rows.Add(row); 
                } 
                 
                ds.Relations.Add("NodeRelation", ds.Tables[0].Columns["ID"], ds.Tables[0].Columns["ParentID"]); 
                 
                RadTreeView1.DataSource = ds; 
                RadTreeView1.DataFieldID = "ID"
                RadTreeView1.DataFieldParentID = "ParentID"
                RadTreeView1.DataTextField = "Title"
                RadTreeView1.DataBind(); 
            } 
                     
                     
          } 
        </script> 
     
    <asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain"
    <rad:RadTreeView ID="RadTreeView1" runat="server"  > 
    </rad:RadTreeView> 
                 
    </asp:Content> 
     

    And now, the TreeView displays the proper hierarchy :

      - News
       - Politics
       - Sports
       - Events

    Thanks for the advice.

    Regards,

    Eric

  7. Bob
    Bob avatar
    55 posts
    Member since:
    Apr 2008

    Posted 24 Apr 2008 Link to this post

    This is a great solution.  I'd like to see Telerik add the functionality to consume wss lists natively, without code.
Back to Top