C# 未存储Web用户控件集合数据
我想创建一个web控件,该控件的集合在ASPX中具有特色。下面的代码有问题 我似乎关闭了对象集合编辑器(集合稳定)。但我的对象设计信息在运行时是设计时无法得到的 当我关闭项目时。所以在某种程度上,信息将在设计过程中被保存 当我在aspx文件中打开项目文件时,也不是什么。Designer.cs在文件中的任何记录中都不一致 我想在下面的图片中显示,这种情况是部分的 基于以上,或者如asp.net集合中的示例所示,示例集合上的列表可以修复或等待您的建议 这是代码C# 未存储Web用户控件集合数据,c#,asp.net,user-controls,C#,Asp.net,User Controls,我想创建一个web控件,该控件的集合在ASPX中具有特色。下面的代码有问题 我似乎关闭了对象集合编辑器(集合稳定)。但我的对象设计信息在运行时是设计时无法得到的 当我关闭项目时。所以在某种程度上,信息将在设计过程中被保存 当我在aspx文件中打开项目文件时,也不是什么。Designer.cs在文件中的任何记录中都不一致 我想在下面的图片中显示,这种情况是部分的 基于以上,或者如asp.net集合中的示例所示,示例集合上的列表可以修复或等待您的建议 这是代码 //***************
//******************************************************Rol.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SANNET.ToolBox.TemelRoller
{/*
[ControlBuilder(typeof(ListItemControlBuilder))]
[ParseChildren(true, "Text")]*/
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Rol
{
private string rolAdi;
private AksiyonTuru aksiyonIcinKullan;
private EfektTuru iseYapilacak;
private string hataMesaji;
private IOzelEfekt ozelEfekt;
public String RolAdi { get { return rolAdi; } set { rolAdi = value; } }
public AksiyonTuru AksiyonIcinKullan { get { return aksiyonIcinKullan; } set { aksiyonIcinKullan = value; } }
public EfektTuru IseYapilacak { get { return iseYapilacak; } set { iseYapilacak = value; } }
public String HataMesaji { get { return hataMesaji; } set { hataMesaji = value; } }
public IOzelEfekt OzelEfekt { get { return ozelEfekt; } set { ozelEfekt = value; } }
public Rol()
{
RolAdi = "Hicbiri";
}
/*
public string GetAttribute(string key)
{
return (String)ViewState[key];
}
public void SetAttribute(string key, string value)
{
ViewState[key] = value;
}*/
}
}
//******************************************************RolListesi.cs
using SANNET.ToolBox.Yardimcilar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI;
namespace SANNET.ToolBox.TemelRoller
{
//[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class RolListesi : CollectionBase//ICollection<Rol>
{
private Collection<Rol> roller;
private Control parent;
public RolListesi(Control parent)
{
this.parent = parent;
parent.PreRender += parent_PreRender;
parent.Load += parent_PreRender;
roller = new Collection<Rol>();
}
void parent_PreRender(object sender, EventArgs e)
{
RolIslemleri.PreRenderIsle((Control)sender, this);
}
public Control Parent { get { return this.parent; } }
public Rol rolGetir(String rolAdi)
{
foreach (Rol r in roller) {
if (r.RolAdi.Equals(rolAdi))
return r;
}
return null;
}
public bool Contains(String rolAdi)
{
return rolGetir(rolAdi) != null;
}
public Rol this[int index]
{
get { return (Rol)roller[index]; }
}
public void Add(Rol emp)
{
roller.Add(emp);
}
public void Remove(Rol emp)
{
roller.Remove(emp);
}
}
}
//******************************************************RolCollectionEditor.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SANNET.ToolBox.TemelRoller
{
public class RolCollectionEditor : CollectionEditor
{
public RolCollectionEditor(Type type)
: base(type)
{
}
protected override string GetDisplayText(object value)
{
Rol item = new Rol();
item = (Rol)value;
return base.GetDisplayText(string.Format("{0}, {1}", item.RolAdi,
item.AksiyonIcinKullan));
}
}
}
//******************************************************SANButton.cs
using DevExpress.Web.ASPxEditors;
using SANNET.ToolBox.TemelRoller;
using System.ComponentModel;
using System.Web.UI;
namespace SANNET.ToolBox.Bilesenler
{
public class SANButton : ASPxButton, IRolSahibi
{
private RolListesi roller;
/* [Editor(typeof(System.ComponentModel.Design.CollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]*/
[Editor(typeof(RolCollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public RolListesi Roller { get {
if (roller == null)
{
roller = new RolListesi(this);
}
return roller; } }
}
}
/*********************************************************************************************************Rol.cs
使用制度;
使用System.Collections.Generic;
使用系统组件模型;
使用System.Linq;
使用System.Web.UI;
使用System.Web.UI.WebControl;
命名空间SANNET.ToolBox.TemelRoller
{/*
[ControlBuilder(typeof(ListItemControlBuilder))]
[ParseChildren(true,“Text”)]*/
[TypeConverter(typeof(ExpandableObjectConverter))]
公共类Rol
{
私人字符串rolAdi;
私人AksiyonTuru aksiyonIcinKullan;
私人埃菲克图鲁·伊塞亚皮拉卡;
私有字符串hataMesaji;
私人IOzelEfekt ozelEfekt;
公共字符串RolAdi{get{return RolAdi;}set{RolAdi=value;}}
public AksiyonTuru AksiyonIcinKullan{get{return AksiyonIcinKullan;}set{AksiyonIcinKullan=value;}}
public EfektTuru IseYapilacak{get{return IseYapilacak;}set{IseYapilacak=value;}}
公共字符串HataMesaji{get{return HataMesaji;}set{HataMesaji=value;}}
public IOzelEfekt OzelEfekt{get{return OzelEfekt;}set{OzelEfekt=value;}}
公共角色
{
RolAdi=“Hicbiri”;
}
/*
公共字符串GetAttribute(字符串键)
{
返回(字符串)视图状态[键];
}
公共void SetAttribute(字符串键、字符串值)
{
视图状态[键]=值;
}*/
}
}
//******************************************************RolListesi.cs
使用SANNET.ToolBox.Yardimcilar;
使用制度;
使用系统集合;
使用System.Collections.Generic;
使用System.Collections.ObjectModel;
使用系统组件模型;
使用系统、绘图、设计;
使用System.Web.UI;
命名空间SANNET.ToolBox.TemelRoller
{
//[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
公共类RolListesi:CollectionBase//ICollection
{
私人收集滚筒;
私人控股母公司;
公共RolListesi(控制父级)
{
this.parent=parent;
parent.PreRender+=parent_PreRender;
parent.Load+=parent\u PreRender;
滚筒=新集合();
}
void parent_PreRender(对象发送方,事件参数e)
{
预渲染((控制)发送方,此);
}
公共控件父项{get{返回this.Parent;}}
公共Rol rolGetir(字符串rolAdi)
{
foreach(滚柱中的滚柱r){
如果(r.RolAdi等于(RolAdi))
返回r;
}
返回null;
}
公共布尔包含(字符串rolAdi)
{
返回rolGetir(rolAdi)!=null;
}
公共Rol本[int索引]
{
获取{返回(Rol)滚轮[索引];}
}
公共无效添加(Rol emp)
{
添加(emp);
}
公共空间移除(Rol emp)
{
滚筒。移除(emp);
}
}
}
//******************************************************RolCollectionEditor.cs
使用制度;
使用System.Collections.Generic;
使用System.ComponentModel.Design;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间SANNET.ToolBox.TemelRoller
{
公共类RolCollectionEditor:CollectionEditor
{
公共角色集合编辑器(类型)
:基本(类型)
{
}
受保护的覆盖字符串GetDisplayText(对象值)
{
Rol项目=新Rol();
项目=(Rol)值;
返回base.GetDisplayText(string.Format(“{0},{1}”),item.RolAdi,
项目(AksiyonIcinKullan));
}
}
}
//******************************************************SANButton.cs
使用DevExpress.Web.ASPxEditors;
使用SANNET.ToolBox.TemelRoller;
使用系统组件模型;
使用System.Web.UI;
命名空间SANNET.ToolBox.Bilesenler
{
公共类SANButton:ASPxButton,IRolSahibi
{
私人滚筒;
/*[Editor(typeof(System.ComponentModel.Design.CollectionEditor),
typeof(系统.绘图.设计.UITypeEditor))]*/
[编辑(类型)(RolCollectionEditor),
typeof(系统.绘图.设计.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
公共滚动体SI滚动体{get{
如果(滚轮==null)
{
辊子=新辊子(本);
}
返回辊;}}
}
}
答案是
[PersistenceMode(PersistenceMode.InnerProperty)]
下面是使用示例
private Roller roller;
[Editor(typeof(RolCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public Roller Roller
{
get
{
if (roller == null)
{
roller = new Roller();
} return roller;
}
}