asp.net listbox implements the single option to cancel all options

  • 2020-12-07 04:00:35
  • OfStack

The front desk
 
<head runat="server"> 
<title> Department of alternative </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> 
</head> 
<body> 
<form id="Form2" method="post" runat="server"> 
<TABLE style="WIDTH: 600px; POSITION: absolute; HEIGHT: 320px" cellSpacing="0" cellPadding="0" border="0"> 
<TR> 
<TD style="WIDTH: 600px; HEIGHT: 20px"> 
<INPUT id="hide" type="hidden" value="<%=pass()%>"> 
<BUTTON id="ok" onclick="javascript:Ok();" type="button"> determine </BUTTON> 
<BUTTON id="cancel" onclick="javascript:Cancel();" type="button"> cancel </BUTTON> 
<%-- <asp:Button ID="Button1" runat="server" Text=" determine " OnClick="Button1_Click" />--%> 
</TD> 
</TR> 
<TR> 
<TD style="WIDTH: 600px; height: 310px;" vAlign="top" 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"> Selected 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 Departments: </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=" Future generations " 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 don't choose " onclick="cmdDelAll_Click"></asp:button> 
</DIV> 
</TD> 
</TR> 
</TABLE> 
</form> 

</body> 

The background
 
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 to judge  

{ 

// On the left side of the listbox Department of binding  
this.UserList.Items.Clear(); 
this.UserList.Items.Add(new ListItem(" General Chairman's Office ", " General Chairman's Office ")); 
this.UserList.Items.Add(new ListItem(" financial ", " financial ")); 
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 the right  
{ 
bool exist=false;// Determine if there is a department on the right, or add the department on the left 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)// Unselect the right side  
{ 
lstSelEmp.Items.Remove(lstSelEmp.SelectedItem); 
} 
protected void cmdDelAll_Click(object sender, System.EventArgs e)// Unselect all on the right side  
{ 
for(int i=0;i<lstSelEmp.Items.Count; ) 
lstSelEmp.Items.Remove(lstSelEmp.Items[i]); 
} 
protected void cmdAddAll_Click(object sender, System.EventArgs e)// Add them all 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(new ListItem(li.Text,li.Value)); 
} 
} 
public string pass() 
{ 
string txt=""; 
for(int j=0;j < lstSelEmp.Items.Count;j++) 
{ 
txt+=lstSelEmp.Items[j]; 
txt+="','"; 
} 
return txt; 
} 
} 

Related articles: