asp.net listbox to achieve the single Select all cancellation _ practical skills

Source: Internet
Author: User
Front desk
Copy Code code as follows:

<title> Department multiple selection </title>
<meta name= "generator" content= Microsoft Visual Studio.NET 7.0 >
<meta name= "Code_language" content= "C #" >
<meta name= "vs_defaultClientScript" content= "JavaScript" >
<meta name= "vs_targetschema" content= "http://schemas.microsoft.com/intellisense/ie5" >
<script language= "javascript" type= "Text/javascript" >
function Ok ()
{
Window.close ();
Opener.document.all.txtOtherMan.value = window. Form2.hide.value;
}
function Cancel ()
{
Window.close ();
}
</SCRIPT>
<body>
<form id= "Form2" method= "POST" runat= "Server" >
<table style= "width:600px; Position:absolute; height:320px "cellspacing=" 0 "cellpadding=" 0 "border=" 0 ">
<TR>
&LT;TD style= "width:600px; height:20px ">
<input id= "Hide" type= "hidden" value= "<%=pass ()%>" >
<button id= "OK" onclick= "Javascript:ok ();" type= "button" > OK </BUTTON>
<button id= "Cancel" onclick= "Javascript:cancel ();" type= "button" > Cancel </BUTTON>
<%--<asp:button id= "Button1" runat= "Server" text= "OK" onclick= "Button1_Click"/>--%>
</TD>
</TR>
<TR>
&LT;TD style= "width:600px; height:310px "valign=" align= "left" >
<div class= "box" style= "width:600px; height:300px; left:0px; top:0px; " >

<asp:listbox id= "userlist" style= "z-index:105; left:27px; Position:absolute; TOP:56PX "runat=" Server "height=" 201px "width=" 200px "selectionmode=" multiple "datatextfield=" Name "datavaluefield=" Name "></asp:listbox>
<asp:listbox id= "lstselemp" style= "z-index:106; left:317px; Position:absolute; top:58px "runat=" Server "height=" 202px "width=" 211px "></asp:listbox>
<asp:label id= "Label4" style= "z-index:107; left:30px; Position:absolute; top:32px "runat=" Server "cssclass=" tttable "> Selection Department:</asp:label>
<asp:label id= "Label5" style= "z-index:108; left:316px; Position:absolute; TOP:34PX "runat=" Server "cssclass=" tttable "height=" 18px "width=" 108px "> Selected Department:</asp:label>
<asp:button id= "Cmdadd" style= "z-index:109; left:235px; Position:absolute; top:145px "runat=" Server "cssclass=" BSBTTN "height=" 27px "width=" 63px "text=" Add-> "onclick=" Cmdadd_click ">< /asp:button>
<asp:button id= "Cmddel" style= "z-index:110; left:237px; Position:absolute; TOP:184PX "runat=" Server "cssclass=" BSBTTN "height=" 30px "width=" 60px "text=" <-Delete "onclick=" Cmddel_click ">< /asp:button>
<asp:button id= "Cmdaddall" style= "z-index:111; left:238px; Position:absolute; TOP:64PX "runat=" Server "cssclass=" BSBTTN "height=" 30px "width=" 60px "text=" Select All "onclick=" Cmdaddall_click "></ Asp:button>
<asp:button id= "Cmddelall" style= "z-index:112; left:236px; Position:absolute; TOP:104PX "runat=" Server "cssclass=" BSBTTN "height=" 30px "width=" 60px "text=" All not selected "onclick=" Cmddelall_click "></ Asp:button>
</DIV>
</TD>
</TR>
</TABLE>
</form>

</body>

Background
Copy Code code as follows:

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using BLL;
Using Model;
public partial class Boarding_HarmSelRoleEmp:System.Web.UI.Page
{
protected void Page_Load (object sender, System.EventArgs e)
{
if (! IsPostBack)
{

if (BLL. Emailuser.getemailuserbyid (session["username"). ToString ()). usercompany.tostring () = = "Beijing")//Login judgment

{

Left ListBox Binding Department
This. UserList.Items.Clear ();
This. USERLIST.ITEMS.ADD (New ListItem ("Office of the General Chairman", "Office of the Chief Chairman"));
This. USERLIST.ITEMS.ADD (New ListItem ("Finance", "Finance"));
This. USERLIST.ITEMS.ADD (New ListItem ("Market", "market"));
This. USERLIST.ITEMS.ADD (New ListItem ("Administrative", "administrative"));
This. USERLIST.ITEMS.ADD (New ListItem ("It", "it"));
}

}
}
protected void Cmdadd_click (object sender, System.EventArgs e)//Add to right
{
BOOL exist=false;//to determine whether there is on the right side or not, add the left department to the right
foreach (ListItem li in Lstselemp.items)
{
if (li. Value==userlist.selecteditem.value)
{
Exist=true;
}
}
if (Exist==false)
{
LSTSELEMP.ITEMS.ADD (New ListItem (Userlist.selecteditem.text,userlist.selecteditem.value));
}
}
protected void Cmddel_click (object sender, System.EventArgs e)/Cancel right selection
{
LstSelEmp.Items.Remove (Lstselemp.selecteditem);
}
protected void Cmddelall_click (object sender, System.EventArgs e)//all Cancel right selection
{
for (int i=0;i<lstselemp.items.count;)
LstSelEmp.Items.Remove (Lstselemp.items[i]);
}
protected void Cmdaddall_click (object sender, System.EventArgs e)//all added to the right
{
foreach (ListItem li in Userlist.items)
{
BOOL Exist=false;
foreach (ListItem lised in Lstselemp.items)
if (lised. Value==li. Value)
Exist=true;
if (Exist==false)
LstSelEmp.Items.Add (Li, New ListItem. Text,li. Value));
}
}
public String Pass ()
{
String txt= "";
for (int j=0;j < lstselemp.items.count;j++)
{
TXT+=LSTSELEMP.ITEMS[J];
txt+= "', '";
}
return txt;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.