
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
百度搜藏|
新浪VIvi|
365key|
Younote|
搜狐 |
博采中心|
你好BLOG|
亿友网摘|
网摘博客|
POCO网摘|
和讯网摘|
我们在页面上进行ListBox进行左移,右移的数据全部需要按一定的格式临时存储在HiddenField控件中,这样我们可以通过继承IPostBackDataHandler 接口中的LoadPostData方法获取我们临时存储的数据,对ListBox的数据源进行添加,移除等操作。
IPostBackDataHandler
| 1 public bool LoadPostData(string postDataKey, NameValueCollection postCollection) 2 { 3 bool resultValueFlag = false; 4 //移除指定ListItem,并需要添加了Left ListBox列表框中 5 string itemsRemoved = postCollection[this.ClientID + "_REMOVED"]; 6 string[] itemsRemovedCol = itemsRemoved.Split(','); 7 if (itemsRemovedCol != null) 8 { 9 if (itemsRemovedCol.Length > 0 && itemsRemovedCol[0] != "") 10 { 11 for (int i = 0; i < itemsRemovedCol.Length; i++) 12 { 13 string[] itemsRemoveItems = itemsRemovedCol[i].Split('|'); 14 ListItem item = this.SecondListBox.Items.FindByValue(itemsRemoveItems[1]); 15 if (item != null) 16 { 17 this.SecondListBox.Items.Remove(item); 18 } 19 item = this.FirstListBox.Items.FindByValue(itemsRemoveItems[1]); 20 if (item == null) 21 { 22 23 this.FirstListBox.Items.Add(new ListItem(itemsRemoveItems[0], itemsRemoveItems[1])); 24 } 25 resultValueFlag = true; 26 } 27 } 28 } 29 //从客户端添加指定的ListItem 30 string itemsAdded = postCollection[this.ClientID + "_ADDED"]; 31 string[] itemsAddedCol = itemsAdded.Split(','); 32 if (itemsAddedCol != null) 33 { 34 if (itemsAddedCol.Length > 0 && itemsAddedCol[0] != "") 35 { 36 int counter = -1; 37 for (int i = 0; i < itemsAddedCol.Length; i++) 38 { 39 string[] itemsAddItems = itemsAddedCol[i].Split('|'); 40 ListItem item = this.SecondListBox.Items.FindByValue(itemsAddItems[1]); 41 if (item == null) 42 { 43 this.SecondListBox.Items.Add(new ListItem(itemsAddItems[0],itemsAddItems[1])); 44 counter += 1; 45 } 46 item = this.FirstListBox.Items.FindByValue(itemsAddItems[1]); 47 if (item != null) 48 { 49 this.FirstListBox.Items.Remove(item); 50 } 51 } 52 resultValueFlag = counter > -1 ? true : false; 53 } 54 } 55 56 //从客户端中移除指定的ListItem 57 return resultValueFlag; 58 } 59 60 public void RaisePostDataChangedEvent() 61 { 62 //TODO:: 63 } 64 |
| 1<asp:MultiListBox ID="ListBox1" runat="server" Rows="10" Width="250px" Height="200px" DataTextField="UserName" DataValueField="UserID" SelectionMode="Multiple"> 2 <FirstListBox><StyleSheet Width="100px" /></FirstListBox> 3 <SecondListBox><StyleSheet Width="100px" /></SecondListBox> 4 </asp:MultiListBox> 5 Submit 1protected void Page_Load(object sender, EventArgs e) 2 { 3 if (Page.IsPostBack) 4 return; 5 ListBox1.FirstListBox.DataSource = LoadData(1, 5); 6 ListBox1.SecondListBox.DataSource = LoadData(6, 10); 7 ListBox1.DataBind(); 8} 9protected void Button1_Click(object sender, EventArgs e) 10 { 11 Response.Write("您SecondList选择的值为:<br/>"); 12 foreach (ListItem item in this.ListBox1.SecondListBox.Items) 13 { 14 Response.Write(item.Text + ":" + item.Value + "<br/>"); 15 } 16 Response.Write("您FirstList选择的值为:<br/>"); 17 foreach (ListItem item in this.ListBox1.FirstListBox.Items) 18 { 19 Response.Write(item.Text + ":" + item.Value + "<br/>"); 20 } 21 } 22 |