js控制菜单位置问题

loselovegirl 2009-12-21 04:21:31
先说问题,我写完这个代码以后,是用于自由调整textbox里面的数据的位置,然后做保存的,目前做出来以后,按图标它不动,就是不调整位置,但是以前是好的,不知道为什么,求哪个大大帮忙看下,代码如下,代码中有NHbiernate,我觉得是JS的问题
function SetData()
{
var strorder = "";
var ord = 0;
var orders = $get("<%=lboxOrder.ClientID %>");
for (var i=0;i<orders.options.length;i++)
{
strorder += orders.options[i].value;
ord++;
if (ord < orders.options.length)
strorder += ",";
}
$get("<%=txtOrd.ClientID %>").value = strorder;
return true;
}

function UpOrder()
{
var orders = $get("<%=lboxOrder.ClientID %>");
var rid = "";
var rname = "";
var ind = 0;
var rids = new Array();
var rnames = new Array();
for (var i=0;i<orders.options.length;i++)
{
if (orders.options[i].selected)
{
rid = orders.options[i].value;
rname = orders.options[i].text;
orders.options.remove(i);
ind = i - 1;
i--;
}
else{
rids[i] = orders.options[i].value;
rnames[i] = orders.options[i].text;
}
}

for (var i=orders.options.length-1;i>=0;i--)
{
orders.options.remove(i);
}

var isUp = false;
for (var i=0;i<rids.length;i++)
{
if (i==ind && !isUp)
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rname;
oNewItem.value = rid;
oNewItem.selected = true;
isUp = true;
i--;
}
else
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rnames[i];
oNewItem.value = rids[i];
}
}

if (!isUp)
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rname;
oNewItem.value = rid;
oNewItem.selected = true;
isUp = true;

}
SetData();
}

function DownOrder()
{
var orders = $get("<%=lboxOrder.ClientID %>");
var rid = "";
var rname = "";
var ind = 0;
var rids = new Array();
var rnames = new Array();
for (var i=0;i<orders.options.length;i++)
{
if (orders.options[i].selected)
{
rid = orders.options[i].value;
rname = orders.options[i].text;
orders.options.remove(i);
ind = i + 1;
i--;
}
else{
rids[i] = orders.options[i].value;
rnames[i] = orders.options[i].text;
}
}

for (var i=orders.options.length-1;i>=0;i--)
{
orders.options.remove(i);
}

var isdown = false;
for (var i=0;i<rids.length;i++)
{
if (i==ind && !isdown)
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rname;
oNewItem.value = rid;
oNewItem.selected = true;
isdown = true;
i--;
}
else
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rnames[i];
oNewItem.value = rids[i];
}
}

if (!isdown)
{
var oNewItem = document.createElement("OPTION");
orders.options.add(oNewItem);
oNewItem.innerText = rname;
oNewItem.value = rid;
oNewItem.selected = true;
isdown = true;

}
SetData();
}

后台的:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}

private void BindData()
{
string hql = "FROM WDMenu AS w WHERE w.B2bUserId = :B2bUserId";
string hqlOrderBy = " ORDER BY w.OrderNum Desc"; //排序
NHibernate.IQuery q = Session17u_netRead.CreateQuery(hql + hqlOrderBy)
.SetParameter("B2bUserId", CurrentMember.Id);
IList<WDMenu> roomtypes = q.List<WDMenu>();
if (roomtypes != null && roomtypes.Count > 0)
{
lblRoomCount.Text = roomtypes.Count.ToString();
lboxOrder.DataTextField = "Name";
lboxOrder.DataValueField = "Id";
lboxOrder.DataSource = roomtypes;
lboxOrder.DataBind();
lboxOrder.Items[0].Selected = true;
//保存当前排序的状态
txtOrd.Text = GetCurrentState();
}
}
/// <summary>
/// 得到当前排序状态
/// </summary>
/// <returns></returns>
private string GetCurrentState()
{
string state = "";
int ord = 0;
for (int i = 0; i < lboxOrder.Items.Count; i++)
{
state += lboxOrder.Items[i].Value;
ord++;
if (ord < lboxOrder.Items.Count)
state += ",";
}
return state;
}

protected void btnSaveOrder_Click(object sender, EventArgs e)
{
//先验证排序是否已经调整,如调整则重新对所有房型排序
string CState = GetCurrentState();
if (txtOrd.Text.Trim() != CState)
{
NHibernate.ITransaction tran = Session17u_netWrite.BeginTransaction();
try
{
string[] CStateOrd = txtOrd.Text.Trim().Split(',');
for (int i = 0; i < CStateOrd.Length; i++)
{
WDMenu wd = Session17u_netWrite.Get<WDMenu>(int.Parse(CStateOrd[i]));
wd.OrderNum = 10 * (i + 1);
Session17u_netWrite.Update(wd);
}
tran.Commit();
ExecStartupScript("$(function() {D.RefreshPageData();P.cancel();});");//RefreshPageData
//AlertSuccess("调整显示顺序成功!", "RefreshPageData()");
}
catch (ModelException ex)
{
tran.Rollback();
throw new ModelException(ex.ToString());
}
}
else
{
//ExecStartupScript("$(function() {P.cancel();});");//RefreshPageData
AlertSuccess("调整显示顺序成功!");
}
}
...全文
99 5 打赏 收藏 举报
写回复
5 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
loselovegirl 2009-12-22
  • 打赏
  • 举报
回复
这个代码不用了吧,希望有人能给个JS调整菜单中列位置的代码,我参考下
loselovegirl 2009-12-22
  • 打赏
  • 举报
回复
看过了,代码上面没有错,在模板页的时候有一个调用jq的,那里报错的,单独运行会报错,整体运行不会,无语了
千游 2009-12-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 haiyong_sea 的回复:]
代码也太多了吧,提一些重点
[/Quote]
同意
真哥哥 2009-12-21
  • 打赏
  • 举报
回复
代码也太多了吧,提一些重点
sunxing007 2009-12-21
  • 打赏
  • 举报
回复
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2009-12-21 04:21
社区公告
暂无公告