左右两个列表框项之间的添加、移除、上下移动
2009-07-12 21:24
519 查看
左右两个列表框项之间的添加、移除、上下移动的JS脚本:
<script language="javascript" type="text/javascript">
// <!CDATA[
//双击source某项时添加该项到destination
//双击list某项时删除该项
//将source选择项全部添加到destination
//将source所有项全部添加到destination
//将list选择项全部删除
//删除list所有项
//上移list某选择项
//下移list某选择项
//保存list列表框所有项到hf隐藏域
//双击lstSource列表框
//双击lstDestination列表框
//添加(从左往右)
//全部添加(从左往右)
//移除(从右往左)
//全部移除(从右往左)
//上移
//下移
//保存所有的列表框数据项到隐藏域
// ]]>
</script>但是,通过JS脚本只是改变了列表框在客户端的各项内容,如果想保持列表框服务器端和客户端的内容一致,需借助HiddenField空间。页面元素代码如下:
<table>
<tr>
<td>
<asp:ListBox ID="lstSource" runat="server" Height="169px" Width="74px"
SelectionMode="Multiple" ondblclick="return lstSource_dblclick()">
</asp:ListBox>
</td>
<td>
<table class="style1">
<tr>
<td>
<input id="btnAdd" type="button" value="添加" onclick="return btnAdd_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnAddAll" type="button" value="全部添加" onclick="return btnAddAll_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnDelete" type="button" value="移除" onclick="return btnDelete_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnDeleteAll" type="button" value="全部移除" onclick="return btnDeleteAll_onclick()" /></td>
</tr>
</table>
</td>
<td>
<asp:ListBox ID="lstDestination" runat="server" Height="169px" Width="74px"
SelectionMode="Multiple" ondblclick="return lstDestination_dblclick()">
</asp:ListBox>
</td>
<td>
<table class="style1">
<tr>
<td>
<input id="btnUp" type="button" value="上移"
onclick="return btnUp_onclick()" /></td>
</tr>
<tr>
<td>
<input
id="btnDown" type="button" value="下移" onclick="return btnDown_onclick()" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
<td align="center">
<asp:Button
ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="确 定"
OnClientClick="SaveAllList()" UseSubmitBehavior="False" />
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:HiddenField ID="hfListSource" runat="server" />
<asp:HiddenField ID="hfListDestination" runat="server" />后台代码CS文件的Page_Load事件代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSource();
BindDestination();
}
else
{
lstSource.Items.Clear();
string[] list = hfListSource.Value.Split('#');
for (int i = 0; i < list.Length - 1; i++)
{
string[] t = list[i].Split(':');
lstSource.Items.Add(new ListItem(t[0], t[1]));
}
lstDestination.Items.Clear();
list = hfListDestination.Value.Split('#');
for (int i = 0; i < list.Length - 1; i++)
{
string[] t = list[i].Split(':');
lstDestination.Items.Add(new ListItem(t[0], t[1]));
}
}
}
<script language="javascript" type="text/javascript">
// <!CDATA[
//双击source某项时添加该项到destination
//双击list某项时删除该项
//将source选择项全部添加到destination
//将source所有项全部添加到destination
//将list选择项全部删除
//删除list所有项
//上移list某选择项
//下移list某选择项
//保存list列表框所有项到hf隐藏域
//双击lstSource列表框
//双击lstDestination列表框
//添加(从左往右)
//全部添加(从左往右)
//移除(从右往左)
//全部移除(从右往左)
//上移
//下移
//保存所有的列表框数据项到隐藏域
// ]]>
</script>但是,通过JS脚本只是改变了列表框在客户端的各项内容,如果想保持列表框服务器端和客户端的内容一致,需借助HiddenField空间。页面元素代码如下:
<table>
<tr>
<td>
<asp:ListBox ID="lstSource" runat="server" Height="169px" Width="74px"
SelectionMode="Multiple" ondblclick="return lstSource_dblclick()">
</asp:ListBox>
</td>
<td>
<table class="style1">
<tr>
<td>
<input id="btnAdd" type="button" value="添加" onclick="return btnAdd_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnAddAll" type="button" value="全部添加" onclick="return btnAddAll_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnDelete" type="button" value="移除" onclick="return btnDelete_onclick()" /></td>
</tr>
<tr>
<td>
<input id="btnDeleteAll" type="button" value="全部移除" onclick="return btnDeleteAll_onclick()" /></td>
</tr>
</table>
</td>
<td>
<asp:ListBox ID="lstDestination" runat="server" Height="169px" Width="74px"
SelectionMode="Multiple" ondblclick="return lstDestination_dblclick()">
</asp:ListBox>
</td>
<td>
<table class="style1">
<tr>
<td>
<input id="btnUp" type="button" value="上移"
onclick="return btnUp_onclick()" /></td>
</tr>
<tr>
<td>
<input
id="btnDown" type="button" value="下移" onclick="return btnDown_onclick()" /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
<td align="center">
<asp:Button
ID="btnSubmit" runat="server" onclick="btnSubmit_Click" Text="确 定"
OnClientClick="SaveAllList()" UseSubmitBehavior="False" />
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
<asp:HiddenField ID="hfListSource" runat="server" />
<asp:HiddenField ID="hfListDestination" runat="server" />后台代码CS文件的Page_Load事件代码如下:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindSource();
BindDestination();
}
else
{
lstSource.Items.Clear();
string[] list = hfListSource.Value.Split('#');
for (int i = 0; i < list.Length - 1; i++)
{
string[] t = list[i].Split(':');
lstSource.Items.Add(new ListItem(t[0], t[1]));
}
lstDestination.Items.Clear();
list = hfListDestination.Value.Split('#');
for (int i = 0; i < list.Length - 1; i++)
{
string[] t = list[i].Split(':');
lstDestination.Items.Add(new ListItem(t[0], t[1]));
}
}
}
相关文章推荐
- 两个多选框(select)之间值的左右上下移动
- 两个多选框(select)之间值的左右上下移动
- 两个select 左右添加,上下移动
- 两个多选框(select)之间值的左右上下移动
- C#开发学习笔记:C#中实现两个GridControl之间的数据拖拽以及同一个GridControl中的数据行上下移动
- JS动态的把左边列表添加到右边的实现代码(可上下移动)
- 左右两个Select列表框交换数据的JS代码,上下左右都可以移动数据,还可以置顶、沉底,相信大家见到过,但觉得挺实用,与大家分享。
- 【JavaScript】列表(Select)选项(Option)的移动(上下左右)
- 实现左右两边用户添加、删除、调位置(上下移动)、排序等的功能
- jquery书写左右两个多选下拉列表交换移除功能
- JavaScript Select和Option列表元素上下左右移动
- ztree 两个tree之间添加,移除,搜索
- 【JavaScript】列表(Select)选项(Option)的移动(上下左右)
- jquery 两个select控件左右移动并上下移动
- JS动态的把左边列表添加到右边的实现代码(可上下移动)
- table数据表格添加checkbox进行数据进行两个表格左右移动。
- 列表框的左右上下移动
- 两个UIViewController之间的翻转可以用动画效果翻转(上下,左右)--跨界面之间的视图切换