当前位置: 编程技术>.net/c#/asp.net
asp.net listbox实现单选全选取消
来源: 互联网 发布时间:2014-08-25
本文导语: 前台 代码如下: 部门多选 function Ok() { window.close(); opener.document.all.txtOtherMan.value = window.Form2.hide.value; } function Cancel() { window.close(); } 确定 取消 选取部门: 已选定部门: 后台 代码如下: using System; using S...
前台
部门多选
function Ok()
{
window.close();
opener.document.all.txtOtherMan.value = window.Form2.hide.value;
}
function Cancel()
{
window.close();
}
确定
取消
选取部门:
已选定部门:
后台
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() == "北京")//登录判断
{
//左侧listbox绑定部门
this.UserList.Items.Clear();
this.UserList.Items.Add(new ListItem("总董事长办公室", "总董事长办公室"));
this.UserList.Items.Add(new ListItem("财务", "财务"));
this.UserList.Items.Add(new ListItem("市场", "市场"));
this.UserList.Items.Add(new ListItem("行政", "行政"));
this.UserList.Items.Add(new ListItem("IT", "IT"));
}
}
}
protected void cmdAdd_Click(object sender, System.EventArgs e)//添加到右侧
{
bool exist=false;//判断在右侧是否存在,不存在则将左侧部门添加到右侧
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)//取消右侧选择
{
lstSelEmp.Items.Remove(lstSelEmp.SelectedItem);
}
protected void cmdDelAll_Click(object sender, System.EventArgs e)//全部取消右侧选择
{
for(int i=0;i
代码如下:
部门多选
function Ok()
{
window.close();
opener.document.all.txtOtherMan.value = window.Form2.hide.value;
}
function Cancel()
{
window.close();
}
确定
取消
选取部门:
已选定部门:
后台
代码如下:
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() == "北京")//登录判断
{
//左侧listbox绑定部门
this.UserList.Items.Clear();
this.UserList.Items.Add(new ListItem("总董事长办公室", "总董事长办公室"));
this.UserList.Items.Add(new ListItem("财务", "财务"));
this.UserList.Items.Add(new ListItem("市场", "市场"));
this.UserList.Items.Add(new ListItem("行政", "行政"));
this.UserList.Items.Add(new ListItem("IT", "IT"));
}
}
}
protected void cmdAdd_Click(object sender, System.EventArgs e)//添加到右侧
{
bool exist=false;//判断在右侧是否存在,不存在则将左侧部门添加到右侧
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)//取消右侧选择
{
lstSelEmp.Items.Remove(lstSelEmp.SelectedItem);
}
protected void cmdDelAll_Click(object sender, System.EventArgs e)//全部取消右侧选择
{
for(int i=0;i