listBox 搜索左右移动

1 <td align="left" width="50%"> 
2             查询:<asp:TextBox ID="SacffSearch" runat="server" Width="54px"></asp:TextBox><asp:Button runat="server" Text="搜索" id="tbnSearch" OnClick="tbnSearch_Click"></asp:Button>
3              <asp:ListBox ID="AllPeople" runat="server" Height="100px" Width="148px" AutoPostBack="true" SelectionMode="Multiple" OnSelectedIndexChanged="AllPeople_SelectedIndexChanged"></asp:ListBox>
4         </td> 
View Code

 

 listbox左右移动带搜索功能

 

后台代码

 

 1  protected void PersonLMove_Click(object sender, EventArgs e)
 2         {
 3             IList<ListItem> list = new List<ListItem>();
 4             var count = AllPeople.Items.Count;
 5             for (int i = 0; i < count; i++)
 6             {
 7                 var onepeopleitem = AllPeople.Items[i];
 8                 if (onepeopleitem.Selected)
 9                 {
10                     NeedExamStaff.Items.Add(onepeopleitem);
11                     list.Add(onepeopleitem);
12                 }
13             }
14             for (int i = 0; i < list.Count(); i++)
15             {
16                 AllPeople.Items.Remove(list[i]);
17             }
18             NeedStaffNumber.Text = NeedExamStaff.Items.Count.ToString();
19 
20         }
21 
22         protected void PersonRMove_Click(object sender, EventArgs e)
23         {
24             IList<ListItem> list = new List<ListItem>();
25             var count = NeedExamStaff.Items.Count;
26             for (int i = 0; i < NeedExamStaff.Items.Count; i++)
27             {
28                 var onepeopleitem = NeedExamStaff.Items[i];
29                 if (onepeopleitem.Selected)
30                 {
31                     AllPeople.Items.Add(onepeopleitem);
32                     list.Add(onepeopleitem);
33                 }
34             }
35             for (int i = 0; i < list.Count(); i++)
36             {
37                 NeedExamStaff.Items.Remove(list[i]);
38             }
39 
40             NeedStaffNumber.Text = NeedExamStaff.Items.Count.ToString();
41         }
42 
43         protected void PersonLAll_Click(object sender, EventArgs e)
44         {
45             IList<ListItem> list = new List<ListItem>();
46             var count = AllPeople.Items.Count;
47             for (int i = 0; i < count; i++)
48             {
49                 var onepeopleitem = AllPeople.Items[i];
50                 NeedExamStaff.Items.Add(onepeopleitem);
51                 list.Add(onepeopleitem);
52 
53             }
54             for (int i = 0; i < list.Count(); i++)
55             {
56                 AllPeople.Items.Remove(list[i]);
57             }
58             NeedStaffNumber.Text = NeedExamStaff.Items.Count.ToString();
59         }
60 
61         protected void PersonRAll_Click(object sender, EventArgs e)
62         {
63             IList<ListItem> list = new List<ListItem>();
64             var count = NeedExamStaff.Items.Count;
65             for (int i = 0; i < NeedExamStaff.Items.Count; i++)
66             {
67                 var onepeopleitem = NeedExamStaff.Items[i];
68                 AllPeople.Items.Add(onepeopleitem);
69                 list.Add(onepeopleitem);
70             }
71             for (int i = 0; i < list.Count(); i++)
72             {
73                 NeedExamStaff.Items.Remove(list[i]);
74             }
75 
76             NeedStaffNumber.Text = NeedExamStaff.Items.Count.ToString();
77         }
View Code

 

 1   protected void tbnSearch_Click(object sender, EventArgs e)
 2         {
 3             var searchContnet = this.SacffSearch.Text.TrimEnd(',').Split(',');
 4             var count = AllPeople.Items.Count;
 5 
 6             for (int k = 0; k < searchContnet.Length; k++)
 7             {
 8                 var j = 0;
 9                 for (int i = 0; i < count; i++)
10                 {
11                     if (AllPeople.Items[i].Text.Trim() == searchContnet[k].Trim())
12                     {
13                         AllPeople.Items[i].Selected = true;
14                         AllPeople.SelectedIndex = i;
15                         break;
16                     }
17                 }
18                 if (AllPeople.SelectedIndex > 0)
19                 {
20                     int idx = AllPeople.SelectedIndex;
21                     var SelectedItem = AllPeople.SelectedItem;
22                     AllPeople.Items.Insert(0, new ListItem(SelectedItem.Text, SelectedItem.Value));
23                     AllPeople.Items.RemoveAt(AllPeople.SelectedIndex);
24                     AllPeople.SelectedIndex = 0;
25                 }
26             }
27 
28         }
View Code

 

转载于:https://www.cnblogs.com/yuanjiehot/p/4334167.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值