protected override object SaveViewState() { var valuestr = Page.Request.Form["tb" + this.ClientID]; if (!string.IsNullOrEmpty(valuestr)) { var values = valuestr.Split(','); var temp = Items.Where(t => values.Contains(t.Value)).ToList(); foreach (var item in temp) { item.Selected = true; } } return new object[] { base.SaveViewState(), Items }; } protected override void LoadViewState(object savedState) { object[] vState = (object[])savedState; if (vState[0] != null) base.LoadViewState(vState[0]); if (vState[1] != null) Items = (List<Select2Item>)vState[1]; }
7.单选和复选的设置,在js中控制
添加属性
[Description("获取和设置多选"), DefaultValue(true), Browsable(true), Category("杂项")]
public bool Multiple { get; set; }
在OnPreRender代码中你会发现Multiple属性会影响div的mul属性值,从而判断是否多选(默认多选)
8.其它说明
private static readonly string STYLE_TEMPLATE = "<link href=https://www.jb51.net/article/\"{0}\" rel=https://www.jb51.net/article/\"stylesheet\" type=https://www.jb51.net/article/\"text/css\" />\r\n";
private static readonly string SCRIPT_TEMPLATE = "<script type=https://www.jb51.net/article/\"text/javascript\" src=https://www.jb51.net/article/\"{0}\"></script>\r\n";
效果图: