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

RadTreeView - SPDataSource

6 Answers 200 Views
Sharepoint Integration
This is a migrated thread and some comments may be shown as answers.
Eric Mauvais
Top achievements
Rank 1
Eric Mauvais asked on 26 Mar 2008, 04:29 PM
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

6 Answers, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 27 Mar 2008, 07:55 AM
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
0
Eric Mauvais
Top achievements
Rank 1
answered on 27 Mar 2008, 03:58 PM
No, they are displayed like this :

- News
- Politics
- Sports
- Events



They're on the same level.
0
Nikolay
Telerik team
answered on 28 Mar 2008, 04:52 PM
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
0
Sakari Hilama
Top achievements
Rank 1
answered on 31 Mar 2008, 06:26 AM
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
0
Eric Mauvais
Top achievements
Rank 1
answered on 31 Mar 2008, 09:08 AM
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

0
Bob
Top achievements
Rank 1
answered on 24 Apr 2008, 03:28 PM
This is a great solution.  I'd like to see Telerik add the functionality to consume wss lists natively, without code.
Tags
Sharepoint Integration
Asked by
Eric Mauvais
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Eric Mauvais
Top achievements
Rank 1
Sakari Hilama
Top achievements
Rank 1
Bob
Top achievements
Rank 1
Share this question
or