zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    matrix_2015_1 138
    2014ACM/ICPC亚洲区广州站 北大命题
    无向图的联通分量
    5.1 基础题目选讲
    URAL
    Codeforces Round #274 (Div. 2)
    后缀数组
    poj 1661 help jimmy dp
    hdu 1676 Full Tank? 限制最短路 dp 蛮有技巧的~
    hdu 1023 Train Problem II 双向广搜
  • 原文地址:https://www.cnblogs.com/yuanjiehot/p/4334167.html
Copyright © 2011-2022 走看看