您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这期内容当中小编将会给大家带来有关asp.net中怎么利用listbox实现单选全选取消,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
前台
<head runat="server"> <title>部门多选</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 cellSpacing="0" cellPadding="0" border="0"> <TR> <TD > <INPUT id="hide" type="hidden" value="<%=pass()%>"> <BUTTON id="ok" onclick="javascript:Ok();" type="button">确定</BUTTON> <BUTTON id="cancel" onclick="javascript:Cancel();" type="button">取消</BUTTON> <%-- <asp:Button ID="Button1" runat="server" Text="确定" OnClick="Button1_Click" />--%> </TD> </TR> <TR> <TD vAlign="top" align="left"> <DIV class="box" > <asp:listbox id="UserList" runat="server" Height="201px" Width="200px" SelectionMode="Multiple" DataTextField="Name" DataValueField="Name"></asp:listbox> <asp:listbox id="lstSelEmp" runat="server" Height="202px" Width="211px"></asp:listbox> <asp:label id="Label4" runat="server" CssClass="tttable">选取部门:</asp:label> <asp:label id="Label5" runat="server" CssClass="tttable" Height="18px" Width="108px">已选定部门:</asp:label> <asp:button id="cmdAdd" runat="server" CssClass="bsbttn" Height="27px" Width="63px" Text="添加->" onclick="cmdAdd_Click"></asp:button> <asp:button id="cmdDel" runat="server" CssClass="bsbttn" Height="30px" Width="60px" Text="<-删除" onclick="cmdDel_Click"></asp:button> <asp:button id="cmdAddAll" runat="server" CssClass="bsbttn" Height="30px" Width="60px" Text="全选" onclick="cmdAddAll_Click"></asp:button> <asp:button id="cmdDelAll" runat="server" CssClass="bsbttn" Height="30px" Width="60px" Text="全不选" onclick="cmdDelAll_Click"></asp:button> </DIV> </TD> </TR> </TABLE> </form> </body>
后台
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<lstSelEmp.Items.Count; ) lstSelEmp.Items.Remove(lstSelEmp.Items[i]); } protected void cmdAddAll_Click(object sender, System.EventArgs e)//全部添加到右侧 { 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; } }
上述就是小编为大家分享的asp.net中怎么利用listbox实现单选全选取消了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。