我有一个自定义控件,我需要将数组集合存储在视图状态中。数组集合是圆形刻度。怎么进一步?
public class CircularGauge : WebControl
{
private CircularGaugeProperties model = new CircularGaugeProperties();
private List<CircularScales> scales = new List<CircularScales>();
[Browsable(true)]
[Bindable(true)]
[Category("Circular Gauge Properties")]
[Description("Scale values")]
[JsonProperty("scales")]
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<CircularScales> Scales
{
get
{
if (scales == null)
{
scales = new List<CircularScales>();
}
return scales;
}
}
}
其中圆形刻度具有数组集合作为内部属性。然后我如何需要绑定Circularscales中的属性以进行视图状态维护。
答案 0 :(得分:6)
public List<CircularScales> Scales
{
get
{
if (ViewState["scales"] == null)
{
return new List<CircularScales>();
}
return (List<CircularScales>)ViewState["scales"];
}
set
{
ViewState["scales"] = value;
}
}
有用的link关于什么是viewstate以及如何使用它。