create table tb(tid int) insert into tb values(0) insert into tb values(1) insert into tb values(2) insert into tb values(3) insert into tb values(4) insert into tb values(5) insert into tb values(6) insert into tb values(7) insert into tb values(8) insert into tb values(9) insert into tb values(10) insert into tb values(11) insert into tb values(12) goselect m.tid from ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) m, ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) n where n.tid =3 and abs(m.px - n.px) =1 --找到当前ID的前后或一条数据 order by m.tid select m.tid from ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) m, ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) n where n.tid =3 and m.px - n.px=1 --找到当前ID的后条数据 order by m.tidselect m.tid from ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) m, ( select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t ) n where n.tid =3 and m.px - n.px=-1 --找到当前ID的前条数据 order by m.tid 有了这个排序列 互换排序列(PX)就可以实现了
主要是你那个支持拖拉的功能 我感觉html的ui跟li 可以 先在页面上放一个div<div id="divmenu" runat="server"></div>从数据库读出菜单后 在page_load() 写个方法 循环 this.divmenu.InnerHtml=""; for(int i=0;i<dt.Rows.Count;i++) { this.divmenu.InnerHtml+="<ul"+"id=ud"+i+">" for(int j=0;j<dt.Columns.Count) { this.divmenu.InnerHtml+="<li>"+dt.Rows[i][j]+"</li>"; } this.divmenu.InnerHtml+="</ul>"; }后台写js方法来能让他拖拉function order(tt,old,classover,classout) { var sf = arguments.callee; //get the function self var trs = tt.getElementsByTagName('tr'); for(var i=0;i<trs.length;i++) { trs[i].onmousedown = function () { if(this.style.cursor == 'move') { return false; } classout = this.className; this.className = classover; this.style.cursor = 'move'; old = this; } trs[i].onmouseover = function () { if(this.style.cursor == 'move' || !old) { return false; } var tmp_old = old.cloneNode(true); var tmp_now = this.cloneNode(true); var p = this.parentNode; p.replaceChild(tmp_now,old); p.replaceChild(tmp_old,this); sf(tt,tmp_old,classover,classout); } trs[i].onmouseout = function () { //this.className = classout; } trs[i].onmouseup = function () { this.className = classout; this.style.cursor = ''; old = null; } } } 把以上的JS方法里头的Tr改成UL 试试看吧
2. 排序Datalist的数据源
insert into tb values(0)
insert into tb values(1)
insert into tb values(2)
insert into tb values(3)
insert into tb values(4)
insert into tb values(5)
insert into tb values(6)
insert into tb values(7)
insert into tb values(8)
insert into tb values(9)
insert into tb values(10)
insert into tb values(11)
insert into tb values(12)
goselect m.tid from
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) m,
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) n
where n.tid =3 and abs(m.px - n.px) =1 --找到当前ID的前后或一条数据
order by m.tid
select m.tid from
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) m,
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) n
where n.tid =3 and m.px - n.px=1 --找到当前ID的后条数据
order by m.tidselect m.tid from
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) m,
(
select * , px = (select count(1) from tb where tid < t.tid) + 1 from tb t
) n
where n.tid =3 and m.px - n.px=-1 --找到当前ID的前条数据
order by m.tid
有了这个排序列 互换排序列(PX)就可以实现了
先在页面上放一个div<div id="divmenu" runat="server"></div>从数据库读出菜单后
在page_load()
写个方法 循环 this.divmenu.InnerHtml="";
for(int i=0;i<dt.Rows.Count;i++)
{
this.divmenu.InnerHtml+="<ul"+"id=ud"+i+">"
for(int j=0;j<dt.Columns.Count)
{
this.divmenu.InnerHtml+="<li>"+dt.Rows[i][j]+"</li>";
}
this.divmenu.InnerHtml+="</ul>";
}后台写js方法来能让他拖拉function order(tt,old,classover,classout) {
var sf = arguments.callee; //get the function self
var trs = tt.getElementsByTagName('tr');
for(var i=0;i<trs.length;i++) {
trs[i].onmousedown = function () {
if(this.style.cursor == 'move') {
return false;
}
classout = this.className;
this.className = classover;
this.style.cursor = 'move';
old = this;
}
trs[i].onmouseover = function () {
if(this.style.cursor == 'move' || !old) {
return false;
}
var tmp_old = old.cloneNode(true);
var tmp_now = this.cloneNode(true);
var p = this.parentNode;
p.replaceChild(tmp_now,old);
p.replaceChild(tmp_old,this);
sf(tt,tmp_old,classover,classout);
}
trs[i].onmouseout = function () {
//this.className = classout;
}
trs[i].onmouseup = function () {
this.className = classout;
this.style.cursor = '';
old = null;
}
}
}
把以上的JS方法里头的Tr改成UL
试试看吧