日历

2008 8.29 Fri
     12
3456789
10111213141516
17181920212223
24252627282930
31      
«» 2008 - 8 «»

文章搜索

日志文章

2007年10月08日 14:55:55

asp.net2.0 listbox左移、右移、上移、下移、左全移、右全移

//前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ListBox.aspx.cs" Inherits="ListBox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script language="javascript" type="text/javascript">
function btn_right_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");

var count = 0;
for(i = 0; i < select_ListBox_left.length; i ++)
{   count = 0;
if(select_ListBox_left.options.selected)
{
  var temp = document.createElement("option");
  temp.value = select_ListBox_left.value;
  temp.text = select_ListBox_left.text;
  if(select_ListBox_right.length == 0)
  {
    select_ListBox_right.add(temp);;
  }
  else
  {
    for(j = 0; j < select_ListBox_right.length; j ++)
    {
    if(select_ListBox_right.options[j].value == temp.value)
    {
      count++;
    }
    }
    if(count == 0)
    {
    select_ListBox_right.add(temp);
    }
   
  }  
}
}
}

function btn_QuanBu_right_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");
for(i = select_ListBox_right.length; i >= 0; i --)
{  
select_ListBox_right.remove();
}
if(select_ListBox_right.length == 0)
{
for(i = 0; i < select_ListBox_left.length; i ++)
{
  var temp = document.createElement("option");
  temp.value = select_ListBox_left.value;
  temp.text = select_ListBox_left.text;
 
  select_ListBox_right.add(temp);
}
}
}

function btn_left_onclick()
{
var select_ListBox_right = document.getElementById("ListBox_right");
var select_ListBox_left = document.getElementById("ListBox_left");
var tmp = select_ListBox_right.length;
for(i = 0; i < select_ListBox_right.length; i ++)
{
if(select_ListBox_right.options.selected)
{
  select_ListBox_right.remove();
  i--;
}

}
}

function btn_QuanBu_left_onclick()
{
var select_ListBox_left = document.getElementById("ListBox_left");
var select_ListBox_right = document.getElementById("ListBox_right");
for(i = select_ListBox_right.length; i >= 0; i --)
{
select_ListBox_right.remove();
}
}


</script>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <table width="250px" border="0" cellpadding="0" cellspacing="0">
  <tr>
  <td><asp:ListBox ID="ListBox_left" SelectionMode="Multiple" Height="200px" Width="110px" runat="server"></asp:ListBox></td>
  <td>
    <input id="btn_right" type="button" value=" > " onclick="return btn_right_onclick()" />
    <input id="btn_QuanBu_right" type="button" value=" >> " onclick="return btn_QuanBu_right_onclick()" />
    <input id="btn_left" type="button" value=" < " onclick="return btn_left_onclick()" />
    <input id="btn_QuanBu_left" type="button" value=" << " onclick="return btn_QuanBu_left_onclick()" />
    <input id="btn_top" type="button" value=" ↑ " onclick="return btn_top_onclick()" />
    <input id="btn_bottom" type="button" value=" ↓ " onclick="return btn_bottom_onclick()" />
  </td>
  <td><asp:ListBox ID="ListBox_right" SelectionMode="Multiple" Height="200px" Width="110px" runat="server"></asp:ListBox></td>
  </tr>
  </table>
  </div>
  </form>
</body>
</html>
//后台代码:
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;

public partial class ListBox : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
  ListBox_DataBind();
}
}
private void ListBox_DataBind()
{
XBGQWZ.BusinessLayer.T_Modle bus_role = new XBGQWZ.BusinessLayer.T_Modle();
DataSet ds = bus_role.GetList("");
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
  this.ListBox_left.Items.Add(ds.Tables[0].Rows[1].ToString());
}
}
}
转载于:http://www.cnblogs.com/puke/articles/558123.html

Tags: listbox 移动  

类别: asp.net网站类 |  评论(0) |  浏览(1406) |  收藏
发表评论