All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
ASP.NET中Multi——ListBox控件编程详解_.net资料_编程技术

Writer: aaa Article type: Programming skills(编程技巧) Time: 2013/12/18 7:54:37 Browse times: 334 Comment times: 0

ASP.NET中Multi——ListBox控件编程详解_.net资料_编程技术


Head photo

Go homepage
Upload pictures
Write articles

ASP.NET中Multi-ListBox控件编程详解_.net资料_编程技术-你的首页-uuhomepage.com
  开发一个优秀的数据绑定不是一件很容易的事情。刚开始的时候走了一些弯路,一直紧紧咬着 DataBoundControl类不放。最终失望之后冷静下来想到关于DataSource不就是一个数据集合吗?明白之后,有关数据源的问题基本上也解决了。在整个Multi-ListBox控件开发中,我认为最重要的实际上就是页面的生命周期的理解,如果您基本上理解了它的话,那么,基本上,你以后开发一款ASP.NET控件也不是一件很难的事情。我们还是简单了解开发的思路吧。下面是类的设计图(跟本文无关的方法和属性已被我隐藏)
ASP.NET中Multi-ListBox控件编程详解

  在控件的生命周期中,我们主要需要解决用户回发页面的时候保留ListBox的数据源(因为我没有采用复合控件的方式来开发)。因些,我们需要重写控件的SaveViewState, LoadViewState二个方法。

  ViewStates

1 protected override void LoadViewState(object savedState)
2 {
3 if (savedState != null)
4 {
5 Triplet triplet = (Triplet)savedState;
6 base.LoadViewState(triplet.First);
7 Reflector.InvokeMethod(this.FirstListBox.Items, "LoadViewState", new object[] { triplet.Second });
8 Reflector.InvokeMethod(this.SecondListBox.Items, "LoadViewState", new object[] { triplet.Third });
9 }
10 else
11 {
12 base.LoadViewState(null);
13 }
14 this._stateLoaded = true;
15 }
16
17 protected override object SaveViewState()
18 {
19 if (EnableViewState == false)
20 return null;
21 //启用控件视图状态
22 object x = base.SaveViewState();
23 object y = Reflector.InvokeMethod(FirstListBox.Items, "SaveViewState", null);
24 object z = Reflector.InvokeMethod(SecondListBox.Items, "SaveViewState", null);
25 if ((x == null) && (y == null) && (z == null))
26 {
27 return null;
28 }
29 return new Triplet(x, y, z);
30 }




There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.