System.Runtime.Serialization.SerializationException:在C#中创建自定义树视图时

时间:2019-07-11 04:07:37

标签: c# asp.net system.web.ui.webcontrols

我要向[LA中添加一些新功能,而System.Web.UI.WebControls.Treeview.Tag中不可用。所以我通过自定义来扩展Treenode功能。但是,当我在代码中使用System.Web.UI.WebControls.Treenode属性时,我会得到

  

System.Runtime.Serialization.SerializationException

谁能告诉我如何解决此错误?任何链接或线索都会有所帮助。

代码

.Tag

Form.CS

   using System.Web.UI.WebControls; 

   namespace CSASPNETInheritingFromTreeNode 
   { 
      public class CustomTreeView : TreeView 
      { 

         protected override TreeNode CreateNode() 
         { 
            return new CustomTreeNode(this, false); 
         } 
       } 

       public class CustomTreeNode : TreeNode 
       { 

           public object Tag { get; set; } 

        public CustomTreeNode() : base() 
        { 
        } 

      public CustomTreeNode(TreeView owner, bool isRoot) : base(owner, isRoot) 
      { 
      } 


      protected override void LoadViewState(object state) 
      { 
         object[] arrState = state as object[]; 
         this.Tag = arrState[0]; 
         base.LoadViewState(arrState[1]); 
      } 


      protected override object SaveViewState() 
      { 
         object[] arrState = new object[2]; 
         arrState[1] = base.SaveViewState(); 
         arrState[0] = this.Tag; 
         return arrState; 
      } 
  } 
}

在node.Tag中引发错误。如何克服这个错误。

0 个答案:

没有答案