控件開發基礎

博客园 首页 新随笔 联系 订阅 管理

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.UI.Design;
using System.Drawing.Design;
using System.Drawing;

namespace RD.WebControls
{
    [DefaultProperty(
"LeftListDataTextField")]
    [ToolboxData(
"<{0}:TwoListBox runat=server></{0}:TwoListBox>")]
    
public class TwoListBox : CompositeControl
    
{

        
Private Member

        
Public property

        
Override Function

        
Public Function 

        
Private Function
    }

}


TwoListBox.js文件


//左移動所選中的ListBox中的值
function RemoveLeft()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var LeftListBox=document.getElementById(ClentID+"_LeftListBox");
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
for(var i=0;i<RightListBox.options.length;i++)   
    
{   
       
if(RightListBox.options[i].selected==true)   
       
{   
            
var NewOption=document.createElement("option");
            NewOption.value
=RightListBox.options[i].value;
            NewOption.text
=RightListBox.options[i].text;
            LeftListBox.options.add(NewOption);
            RightListBox.options.remove(i);   
            i
--;   
       }
   
    }

    GetListBoxValueToHiden(ClentID);
    
    
return false;
}


//右移動所選中的ListBox中的值
function RemoveRight()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var LeftListBox=document.getElementById(ClentID+"_LeftListBox");
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
for(var i=0;i<LeftListBox.options.length;i++)   
    
{   
       
if(LeftListBox.options[i].selected==true)   
       
{   
            
var NewOption=document.createElement("option");
            NewOption.value
=LeftListBox.options[i].value;
            NewOption.text
=LeftListBox.options[i].text;
            RightListBox.options.add(NewOption);
            LeftListBox.options.remove(i);   
            i
--;   
       }
   
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}


//左移動ListBox中全部的值
function RemoveAllLeft()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var LeftListBox=document.getElementById(ClentID+"_LeftListBox");
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
for(var i=0;i<RightListBox.options.length;)   
    
{   
       
var NewOption=document.createElement("option");
       NewOption.value
=RightListBox.options[i].value;
       NewOption.text
=RightListBox.options[i].text;
       LeftListBox.options.add(NewOption);
       RightListBox.options.remove(i);    
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}


//右移動ListBox中全部的值
function RemoveAllRight()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var LeftListBox=document.getElementById(ClentID+"_LeftListBox");
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
for(var i=0;i<LeftListBox.options.length;)   
    
{   
       
var NewOption=document.createElement("option");
       NewOption.value
=LeftListBox.options[i].value;
       NewOption.text
=LeftListBox.options[i].text;
       RightListBox.options.add(NewOption);
       LeftListBox.options.remove(i);      
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}



//上移動右邊ListBox中選中的值
function RemoveUp()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
for(var i=1;i<RightListBox.options.length;i++)   
    
{   
       
if(RightListBox.options[i].selected==true)
       
{  
           
var strSelectText=  RightListBox.options[i].text;
           
var strSelectValue= RightListBox.options[i].value;
           RightListBox.options[i].text
=RightListBox.options[i-1].text; 
           RightListBox.options[i].value
=RightListBox.options[i-1].value; 
           RightListBox.options[i
-1].text=strSelectText; 
           RightListBox.options[i
-1].value=strSelectValue;  
           RightListBox.options[i].selected
=false
           RightListBox.options[i
-1].selected=true;
       }
 
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}


//下移動右邊ListBox中選中的值
function RemoveDown()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
for(var i=RightListBox.options.length-2;i>=0;i--)   
    
{   
       
if(RightListBox.options[i].selected==true)
       
{  
           
var strSelectText=  RightListBox.options[i].text;
           
var strSelectValue= RightListBox.options[i].value;
           RightListBox.options[i].text
=RightListBox.options[i+1].text; 
           RightListBox.options[i].value
=RightListBox.options[i+1].value; 
           RightListBox.options[i
+1].text=strSelectText; 
           RightListBox.options[i
+1].value=strSelectValue;  
           RightListBox.options[i].selected
=false;    
           RightListBox.options[i
+1].selected=true;
       }
 
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}



//上移到頂端右邊ListBox中選中的值
function RemoveTop()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
var first=RightListBox.firstChild;
    
    
for(var i=1;i<RightListBox.options.length;i++)   
    
{   
       
if(RightListBox.options[i].selected==true)
       
{  
           
var NewOption = RightListBox.removeChild(RightListBox.options[i]); 
           RightListBox.insertBefore(NewOption,first);
           RightListBox.options[
0].selected=true;
       }
 
    }

    GetListBoxValueToHiden(ClentID);
    
return false;
}


//上移到頂端右邊ListBox中選中的值
function RemoveBottom()
{
    
var curElement = event.srcElement;
    
var ClentID=curElement.parentNode.parentNode.parentNode.parentNode.id;
    
var RightListBox=document.getElementById(ClentID+"_RightListBox");
    
    
//循環計算選中的個數
    var SelectLength=0;
    
for(var i=0;i<RightListBox.options.length;i++)   
    
{   
       
if(RightListBox.options[i].selected==true)
          SelectLength
++;
    }

    
    
//順序移動到底端
    for(var i=0;i<RightListBox.options.length;i++)   
    
{   
       
if(RightListBox.options[i].selected==true)
       
{  
           
var NewOption = RightListBox.removeChild(RightListBox.options[i]); 
           i
--;
           NewOption.selected
=false;
           RightListBox.appendChild(NewOption);
       }
 
    }

    
    
//設置選擇
    for(var i=RightListBox.options.length-1;i>=RightListBox.options.length-SelectLength;i--)   
    
{
       RightListBox.options[i].selected
=true;   
    }

    
    GetListBoxValueToHiden(ClentID);
    
return false;
}








//把當前2個ListBox中的值存入2個隱藏文本框中
function GetListBoxValueToHiden(ClentID)
{
  
var LeftListBox=document.getElementById(ClentID+"_LeftListBox");
  
var RightListBox=document.getElementById(ClentID+"_RightListBox");
  
var LeftListBoxValue="";
  
var RigthListBoxValue="";
  
for(var i=0;i<LeftListBox.options.length;i++)   
  
{   
       LeftListBoxValue
+=LeftListBox.options[i].text+"#"+LeftListBox.options[i].value+"#";
  }

  
for(var j=0;j<RightListBox.options.length;j++)   
  
{   
       RigthListBoxValue
+=RightListBox.options[j].text+"#"+RightListBox.options[j].value+"#";
  }

  
  
if(LeftListBoxValue.length>0)
        LeftListBoxValue
=LeftListBoxValue.substring(0,LeftListBoxValue.length-1);
  
if(RigthListBoxValue.length>0)
        RigthListBoxValue
=RigthListBoxValue.substring(0,RigthListBoxValue.length-1);
  
  document.getElementById(ClentID
+"_LeftHiddenTextBox").value=LeftListBoxValue;
  document.getElementById(ClentID
+"_RightHiddenTextBox").value=RigthListBoxValue;
}

posted on 2007-05-22 12:05  ada  阅读(888)  评论(0编辑  收藏  举报