Problem in show a webpart include RadTreeView in Sharepoint 2010

2 posts, 0 answers
  1. Farshad
    Farshad avatar
    6 posts
    Member since:
    Feb 2012

    Posted 08 Feb 2012 Link to this post

    Hi there,

    I have created a webpart include a RadTreeView in Sharepoint 2010. However, when I open the IE to see webpart , I see following  script error:

    Message: 'RadTreeView1_NodeClicked' is undefined
    Line: 1481
    Char: 5
    Code: 0
    My Visual Webpart code(.ascx) is such as follow:
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %> 
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="HiTreeViewUserControl.ascx.cs" Inherits="TreeView.HiTreeView.HiTreeViewUserControl" %>
    <%@ Register Assembly="Telerik.Web.UI, Version=2011.3.1115.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
        Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <%@ Register Assembly="Telerik.Web.UI, Version=2011.3.1115.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4"
        Namespace="Telerik.Web.Design" TagPrefix="telerik" %>
      
    <telerik:RadTreeView ID="RadTreeView1" Runat="server" EnableEmbeddedScripts="true"
            OnClientNodeClicked="RadTreeView1_NodeClicked">
        <DataBindings>
                  <telerik:RadTreeNodeBinding Expanded="True" />
        </DataBindings>
    </telerik:RadTreeView>
      
    <telerik:RadTextBox ID="Dscp" Runat="server" Height="100px" LabelWidth="" 
        Text="Comment" TextMode="MultiLine" Width="325px">
    </telerik:RadTextBox>
    <p>
         </p>
    <telerik:RadButton ID="btnUpdate" runat="server" onclick="btnUpdate_Click" 
        Text="Update">
    </telerik:RadButton>

    The Code Behind is such as follow:
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Telerik.Web.UI;
    using System.Data;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
      
      
    namespace TreeView.HiTreeView
    {
        public partial class HiTreeViewUserControl : UserControl
        {
            static int selectedItem;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                       BindToDataSet(RadTreeView1);
                }
                  
            }
            private static void BindToDataSet(RadTreeView treeView)
            {
                try
                {
                    DataSet dataSet = new DataSet();
      
                    dataSet.Tables.Add("Table");
                    dataSet.Tables[0].Columns.Add("ID", typeof(int));
                    dataSet.Tables[0].Columns.Add("ParentID", typeof(int));
                    dataSet.Tables[0].Columns.Add("Text", typeof(string));
      
                    SPSite spSite = new SPSite(SPContext.Current.Web.Url);
                    SPWeb spWeb = spSite.OpenWeb();
      
                    SPList peopleList = spWeb.Lists["People"];
      
                    foreach (SPListItem people in peopleList.Items)
                    {
                        DataRow row = dataSet.Tables[0].NewRow();
                        row["ID"] = people["ID"];
                        row["Text"] = people["Name"];
                        if (people["Manager"] != null)
                        {
                            int intIndex = Convert.ToInt32(people["Manager"].ToString().IndexOf(';'));
                            row["ParentID"] = Convert.ToInt32(people["Manager"].ToString().Substring(0, intIndex));
                        }
                        dataSet.Tables[0].Rows.Add(row);
                    }
                    treeView.DataTextField = "Text";
                    treeView.DataFieldID = "ID";
                    treeView.DataFieldParentID = "ParentID";
      
                    treeView.DataSource = new HierarchicalDataSet(dataSet, "ID", "ParentID");
                    treeView.DataBind();
                }
                catch(Exception ex)
                {
                }
            }
      
            protected void RadTreeView1_NodeClicked(object sender, EventArgs e)
            {
                SPSite spSite = new SPSite(SPContext.Current.Web.Url);
                SPWeb spWeb = spSite.OpenWeb();
      
                SPList peopleList = spWeb.Lists["People"];
                foreach (SPListItem people in peopleList.Items)
                {
                    if (people["Name"] != null)
                    {
                        if (RadTreeView1.SelectedNode.Text.ToString() == people["Name"].ToString())
                        {
                            if (people["Comment"] != null)
                            {
                                Dscp.Text = people["Comment"].ToString();
                            }
                            else
                            {
                                Dscp.Text = "";
                            }
                        }
                    }
                }
                selectedItem = Convert.ToInt32(RadTreeView1.SelectedNode.Value.ToString());
      
            
      
            protected void btnUpdate_Click(object sender, EventArgs e)
            {
                SPSite spSite = new SPSite(SPContext.Current.Web.Url);
                SPWeb spWeb = spSite.OpenWeb();
                SPListItem itemUpdate = spWeb.Lists["People"].Items[selectedItem];
      
                itemUpdate["Comment"] = Dscp.Text;
                itemUpdate.Update(); 
      
            }
                  
      }
    }

     my email address: kassaiefarshad@yahoo.com


  2. Kalina
    Admin
    Kalina avatar
    918 posts

    Posted 12 Feb 2012 Link to this post

    Hi,

    As far as I understand - you are trying to handle the server-side NodeClick event of the RadTreeView.

    However in your code you have attached the "RadTreeView1_NodeClicked" event handler to OnClientNodeClicked - which is not correct. That is the reason why you receive an error.

    NodeClick is a server-side event and OnClientNodeClicked is a client-side event.


    Regards,
    Kalina
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

Back to Top