下面是自定义的两个类,第二个类是第一个类的集合类//自定义的StringItem类
public class StringItem:WebControl
{
}
//StringItem的集合类
public class StringItems : CollectionBase , IStateManager
{
public StringItems() : base()
{
}
public StringItem this[int index]
{
get
{
return (StringItem)base.List[index];
}
set
{
List[index] = value;
}
}
public void Add(StringItem aItem)
{
this.List.Add(aItem);
} public void Remove(int index)
{
if( index > 0 && index < base.Count - 1 )
{
base.RemoveAt( index );
}
}
}在webpart中这样序列化:[Browsable(true),
Category("自定义"),
DefaultValue(null),
WebPartStorage(Storage.Personal),
FriendlyName("动态菜单项"),
Description("动态菜单项"),
XmlElement(Type=typeof(WebControl)), //<--------------序列处理1
XmlElement(Type=typeof(StringItem)) //<--------------序列处理2
]
public StringItems Strings
{
get
{
if(_Strings == null)
_Strings = new StringItems();
return _Strings;
} }可是在运行的时候还是提示:
Windows SharePoint Services 无法对该 Web 部件进行反序列化。请检查该属性的格式然后再试
(注:webpart的本质就是自定义控件,现在的问题是无法进行xml序列化,跟webpart无关)
到底该怎么序列化才可以阿。
请高手指教
public class StringItem:WebControl
{
}
//StringItem的集合类
public class StringItems : CollectionBase , IStateManager
{
public StringItems() : base()
{
}
public StringItem this[int index]
{
get
{
return (StringItem)base.List[index];
}
set
{
List[index] = value;
}
}
public void Add(StringItem aItem)
{
this.List.Add(aItem);
} public void Remove(int index)
{
if( index > 0 && index < base.Count - 1 )
{
base.RemoveAt( index );
}
}
}在webpart中这样序列化:[Browsable(true),
Category("自定义"),
DefaultValue(null),
WebPartStorage(Storage.Personal),
FriendlyName("动态菜单项"),
Description("动态菜单项"),
XmlElement(Type=typeof(WebControl)), //<--------------序列处理1
XmlElement(Type=typeof(StringItem)) //<--------------序列处理2
]
public StringItems Strings
{
get
{
if(_Strings == null)
_Strings = new StringItems();
return _Strings;
} }可是在运行的时候还是提示:
Windows SharePoint Services 无法对该 Web 部件进行反序列化。请检查该属性的格式然后再试
(注:webpart的本质就是自定义控件,现在的问题是无法进行xml序列化,跟webpart无关)
到底该怎么序列化才可以阿。
请高手指教
{
.........
}加上ISerializable 看看
欢迊来到麦高网-私活兼职首选平台 www.mgao.net
public class StringItems : CollectionBase , IStateManager
.....