惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
雷峰网
雷峰网
博客园_首页
小众软件
小众软件
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
U
Unit 42
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 叶小钗

博客园 - 神话

C#的float型,竟然与SQL中float型不对应(转载) 【源码】非常有用的Vml图像画板(收藏) 为Html 的Select 加一个提示语和输入方法(转载) asp.net三色交替的下拉列表框(转载) 常用正则表达式(收藏) 客户端实现PadLeft 获取某行的字段ID值(GridView模板列) 日历控件收藏 我的博客地图脚本代码 实时统计输入字符数 我的博客地图特效 生成html页面 初次使用ZedGraph 梅花雪日历控件(网络收藏) 树型菜单<仿QQ型菜单>(网络收藏) 面向对象分析(网络收藏) 常用正则表达式(收集)及使用方法 三层架构(非原创) 网页常用代码小技巧五(网络收藏)
ListBox控件上移、下移操作(Ajax)
神话 · 2007-06-22 · via 博客园 - 神话

ListBox控件上移、下移操作,网上找的部分代码,修改成用Ajax实现,记录下供往后开发用,以下是摘抄项目中的部分前台代码*.aspx、SQL脚本、后台代码只给出上移、下移部分操作:

<body>
    
<form id="form1" runat="server">
    
<script>
    
    
var newIndex=0;
       
    
function AddDepart()
    
{
        
var departName=document.getElementById("tbDepartName").value;
        Member_DepartEdit.AddDep(departName);  
//向部门数据表中插入数据
        BindLstBox();    
    }

    
    
function changepos(obj,index)   //按钮移动操作
    {
        
if(index == -1){  //上移操作
            if (obj.selectedIndex>0){
                obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex
-1));
                newIndex 
= obj.selectedIndex;
                Member_DepartEdit.Sort(obj.options[newIndex
+1].value,obj.options[newIndex].value,"Pre");
            }

        }

    
else if(index == 1){   //下移操作
        if (obj.selectedIndex<obj.options.length-1){
            obj.options(obj.selectedIndex).swapNode(obj.options(obj.selectedIndex
+1));
            newIndex 
= obj.selectedIndex;
            Member_DepartEdit.Sort(obj.options[newIndex
-1].value,obj.options[newIndex].value,"Next");
            }

        }

        BindLstBox();
    }

   
function BindLstBox()
   
{
         
var obj=Member_DepartEdit.BindLstBox();   //获取部门列表
         if(obj!=null)
         
{
            document.all(
"lstBox").length=0;
            
var ds=obj.value;
            
if(ds!=null&&typeof(ds)=="object"&&ds.Tables!=null)
            
{
                
//分别在ListBox上显示
                for(var i=0;i<ds.Tables[0].Rows.length;i++)
                
{
                    
var name=ds.Tables[0].Rows[i].departName;
                    
var id=ds.Tables[0].Rows[i].departID;
                    document.all(
"lstBox").options.add(new Option(name,id));
                }

            }

         }

         document.all(
"lstBox").options[newIndex].selected=true;   //显示移动后的行
   }

    
</script>
    
<div>部门名称:<input type="text" id="tbDepartName" name="tbDepartName" />&nbsp;&nbsp;
    
<input type="button"  id="btnSave" name="btnSave" onclick="AddDepart();" value="添 加"/>
    
<br /><br />
    
<div>
       
<asp:ListBox runat="server" ID="lstBox" Width="120px" Height="150px"></asp:ListBox>
    
</div>
    
<br />
    
<div>
        
<button onclick="changepos(lstBox,-1)" type="button">上移</button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        
<button onclick="changepos(lstBox,1)" type="button">下移</button>
    
</div>
    
</form>
</body>

*.asp.cs

    [AjaxPro.AjaxMethod]
    
public void Sort(Int32 iImpactID,Int32 iDepartID,string strOperate)
    
{
        Department.SetSortDep(iImpactID, iDepartID, strOperate);
    }

数据访问层代码

 SetSortDep

表SQL脚本部分

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Department]'and OBJECTPROPERTY(id, N'IsUserTable'= 1)
drop table [dbo].[Department]
GO

CREATE TABLE [dbo].[Department] (
    
[departID] [int] IDENTITY (11NOT NULL ,
    
[departName] [varchar] (32) COLLATE Chinese_PRC_CI_AS NOT NULL ,
    
[leagueID] [int] NOT NULL ,
    
[visible] [bit] NOT NULL ,
    
[sortDep] [int] NOT NULL 
ON [PRIMARY]
GO

存储过程代码

CREATE proc Dep_SetSort
@ReturnValue int=0 output,
@impactID int,
@depID int,
@operate varchar(10)='Next'
as
if(@operate='Pre')
begin
    
--上移
    update [Department] set sortDep=sortDep+1 where departID=@impactID
    
update [Department] set sortDep=sortDep-1 where departID=@depID
end
if(@operate='Next')
begin
    
--下移
    update [Department] set sortDep=sortDep-1 where departID=@impactID
    
update [Department] set sortDep=sortDep+1 where departID=@depID
end
set @ReturnValue=1
GO