asp.net listbox實現(xiàn)單選全選取消
來源:易賢網(wǎng) 閱讀:861 次 日期:2015-01-14 16:04:19
溫馨提示:易賢網(wǎng)小編為您整理了“asp.net listbox實現(xiàn)單選全選取消”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了asp.net listbox單選全選取消的應(yīng)用,需要的朋友可以參考下

前臺

代碼如下:

<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="">

<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">確定</BUTTON>

<BUTTON id="cancel" onclick="javascript:Cancel();" type="button">取消</BUTTON>

<%-- <asp:Button ID="Button1" runat="server" Text="確定" 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">選取部門:</asp:label>

<asp:label id="Label5" style="Z-INDEX: 108; LEFT: 316px; POSITION: absolute; TOP: 34px" runat="server" CssClass="tttable" Height="18px" Width="108px">已選定部門:</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="添加->" 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="<-刪除" 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="全選" 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="全不選" 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() == "北京")//登錄判斷

{

//左側(cè)listbox綁定部門

this.UserList.Items.Clear();

this.UserList.Items.Add(new ListItem("總董事長辦公室", "總董事長辦公室"));

this.UserList.Items.Add(new ListItem("財務(wù)", "財務(wù)"));

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)//添加到右側(cè)

{

bool exist=false;//判斷在右側(cè)是否存在,不存在則將左側(cè)部門添加到右側(cè)

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)//取消右側(cè)選擇

{

lstSelEmp.Items.Remove(lstSelEmp.SelectedItem);

}

protected void cmdDelAll_Click(object sender, System.EventArgs e)//全部取消右側(cè)選擇

{

for(int i=0;i<lstSelEmp.Items.Count; )

lstSelEmp.Items.Remove(lstSelEmp.Items[i]);

}

protected void cmdAddAll_Click(object sender, System.EventArgs e)//全部添加到右側(cè)

{

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;

}

}

更多信息請查看IT技術(shù)專欄

更多信息請查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機網(wǎng)站地址:asp.net listbox實現(xiàn)單選全選取消
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報警專用圖標(biāo)