集合:
public class DataItem:System.Web.UI.Control , IStateManager
{...}
public class DataItemCollection : CollectionBase, IStateManager
{...}
自定義控件:
[Description(""),
Designer("MyWebControls.ComboBoxDesigner"),
ToolboxData("<{0}:ComboBox runat=server></{0}:ComboBox>")]
public class ComboBox : WebControl, INamingContainer ,IStateManager
{
private DataItemCollection m_items;
...
//集合属性
[DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public DataItemCollection Items
{
get
{
if(m_items == null)
m_items = new DataItemCollection();
return this.m_items;
}
}
...
}
最后在我的页面中通过属性编辑器编辑后声称代码如下:
<cc1:ComboBox id="ComboBox6" runat="server">
<Items>
<cc1:DataItem Value="1" Text="test1" ID="dataItem1"></cc1:DataItem>
<cc1:DataItem Value="2" Text="test2" ID="dataItem2"></cc1:DataItem>
</Items>
</cc1:ComboBox>看似OK了,但是在运行的时候,出现对<Items>无法识别的错误,辗转无法解决,只好请教高手们帮我看看我的做法有什么不妥...
public class DataItem:System.Web.UI.Control , IStateManager
{...}
public class DataItemCollection : CollectionBase, IStateManager
{...}
自定義控件:
[Description(""),
Designer("MyWebControls.ComboBoxDesigner"),
ToolboxData("<{0}:ComboBox runat=server></{0}:ComboBox>")]
public class ComboBox : WebControl, INamingContainer ,IStateManager
{
private DataItemCollection m_items;
...
//集合属性
[DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor(typeof(CollectionEditor), typeof(UITypeEditor))]
public DataItemCollection Items
{
get
{
if(m_items == null)
m_items = new DataItemCollection();
return this.m_items;
}
}
...
}
最后在我的页面中通过属性编辑器编辑后声称代码如下:
<cc1:ComboBox id="ComboBox6" runat="server">
<Items>
<cc1:DataItem Value="1" Text="test1" ID="dataItem1"></cc1:DataItem>
<cc1:DataItem Value="2" Text="test2" ID="dataItem2"></cc1:DataItem>
</Items>
</cc1:ComboBox>看似OK了,但是在运行的时候,出现对<Items>无法识别的错误,辗转无法解决,只好请教高手们帮我看看我的做法有什么不妥...
解决方案 »
- 怎么让treeview的父节点只能选中1个
- GridView 表头如何换行? (例如共8字分两行,每行4字)
- xmlhttp responseText 返回乱码问题!
- Server.Transfer,目标不能是htm文件吗
- 在位置 0 处没有任何行(请教高手,调试过程中遇到的)
- 关于ASP时间比较的问题,谢谢~~
- 求关于一个Button事件的编写
- 我在自定义控件里包含一个DataGrid子控件,DataGrid分页显示,但是分页有问题?
- 我的.net的新手,请问各位大侠,怎样设关于.net的环境????
- asp.net core favicon
- 请教如何能去掉Hyperlink下面的下划线?
- vs2005bate中的treeview如何使用??当选择当前checkbox时相应的节点子节点的checkbox也发生变化。
在.net里,,如果想要自定义模版,,需要用一个叫ITemplate的接口,,private ITemplate _itemTemplate;
[TemplateContainer(typeof(CurrenCyInformation))]
{
get{return _itemTemplate;}
set{_itemTemplate = value;}
}
不知道你明不明白,,你能买到asp.net pro 2002--2003中文合集吗?那个上面有介绍的
<cc1:DataItem Value="1" Text="test1" ID="dataItem1"></cc1:DataItem>
<cc1:DataItem Value="2" Text="test2" ID="dataItem2"></cc1:DataItem>
</cc1:ComboBox>可以去www.metabuilds.com 然后下载一个DefaultButtons 或ComboBox控件的源代码研究一下
[ParseChildren(true)]
public class ComboBoxseehttp://west-wind.com/weblog/posts/200.aspx
對於 micropentium6(小笨|曾经的美好) 兄的帖子我還得鑽研一下,初步看了,沒有抓到要領
public class ComboBox
你的做法會讓我在添加這個自定義控件的時候(還未添加集合屬性內容),出現Creating Error
如何是好
說來好笑,其實我貼出來的代碼都沒有問題的,無怪大家幫不了我
產生錯誤的原因是:在DataItemCollection類中我重載了this屬性,如下:
public DataItem this[int index]
{
get
{
return (DataItem)List[index];
}
set
{
List[index] = value;
}
}
public DataItem this[string ItemValue]
{
get
{
foreach(DataItem di in this)
if(di.Value == ItemValue)
return di;
return null;
}
}
.....
現在細細想來,原因可能是這樣的經過虛列化後,this後的參數都變成了string類型,因此,程序直接從xml中讀取該集合的時候,會出現無法解析的錯誤.好了,謝謝各位盡心的幫忙,因為例子主要是從'saucer(思归) '提供的網站上下載的,所以這裡就主要把分給他了謝謝.