var state=false; function Insert(type) { // 判断选中的是待使用 还是已经在使用 var checkedWait = $("input[class='newsId-wait']:checked"); var wl = checkedWait.length; if (wl <= 0) { alert("请先选中一条记录"); return; } if (wl > 1) { alert("只能选择一条记录"); return; } if (wl == 1) { // 选中待使用 state = true; checkedWait.attr("class", "newsId-using"); if (type == 1) { $("#tab2 tr").eq(3).before(checkedWait.parent().parent().clone()); } else { $("#tab2 tr:last").after(checkedWait.parent().parent().clone()); } checkedWait.parent().parent().remove(); } } $(function () { $("#save").click(function () { if (!state) { alert("你还没有进行过操作"); return; } $("input[class='newsId-using']").each(function () { $(this).prop("checked", true); }); form1.submit(); }); $("#insertFirst").click(function () { Insert(1); }); $("#insertLast").click(function () { Insert(2); }); $("#moveUp").click(function () { var checked = $("input[class='newsId-using']:checked"); if (checked.length != 1) { alert("无法多选,且必须选中一条记录"); } else { var current = checked.parent().parent(); var prev = current.prev(); if (current.index() > 3) { state = true; current.insertBefore(prev); } else { alert("已经是最上"); } } }); $("#moveDown").click(function () { var checked = $("input[class='newsId-using']:checked"); if (checked.length != 1) { alert("无法多选,且必须选中一条记录"); } else { var current = checked.parent().parent(); var next = current.next(); if (current.index() < $("#tab2 tr").length - 1) { state = true; current.insertAfter(next); } else { alert("已经是最下"); } } }); });
<table cellspacing="0" cellpadding="0" class="admintable"> <tr> <td> <table cellspacing="0" cellpadding="0" class="admintable01"> <tr> <td style="width: 20px;"> <img src="../../themes/fixed/admin/images/carfromtable_01.gif" style="margin-top: 2px;" /> </td> <td class="navposi" colspan="4"> <b>位置:</b>焦点图列表 </td> <td style="width: 50px;"> </td> <td style="width: 50px;"> </td> <td style="width: 15px;"> </td> </tr> </table> <div class="scroll"> <table cellspacing="0" cellpadding="0" id="tab1" class="admintable03"> <tr> <td colspan="4"> <span class="use-class">待使用</span> <input type="button" id="insertFirst" value="移动到首行" /> <input type="button" id="insertLast" value="移动到尾行" /> </td> </tr> <tr style="background-color: #edf1fa; color: Blue;"> <td></td><td>编号</td><td>标题</td><td>大图</td> </tr> <asp:Repeater ID="_list" runat="server"> <ItemTemplate> <tr> <td><input class="newsId-wait" type="checkbox" name="newsId" value="<%#Eval("NewsId") %>" /></td> <td><%#Eval("RecordNum") %></td> <td><%#Eval("NewsTitle") %></td> <td style="padding:10px 0px 10px 10px;"> <a href='/Upload/Focus/<%# Path.GetFileNameWithoutExtension(Eval("ImgName").ToString())+"big"+Path.GetExtension(Eval("ImgName").ToString()) %>' target="_blank"> <img src='/Upload/Focus/<%# Path.GetFileNameWithoutExtension(Eval("ImgName").ToString())+"big"+Path.GetExtension(Eval("ImgName").ToString()) %>' /> </a> </td> </tr> </ItemTemplate> </asp:Repeater> </table> <div id="sep"></div> <form id="form1" runat="server" method="post"> <table cellspacing="0" cellpadding="0" id="tab2" class="admintable03"> <%--<tr><td colspan="4">正在使用</td></tr>--%> <tr> <td colspan="4"> <span class="use-class">正在使用</span> <input type="button" id="moveUp" value="向上移动" /> <input type="button" id="moveDown" value="向下移动" /> <input type="button" id="save" value="保存" style="font-weight:700;" /> <span style="color:Red;"><%=Message %></span> </td> </tr> <tr><td colspan="4" style="height:25px;"></td></tr> <tr style="background-color: #edf1fa; color: Blue;"> <td></td><td>编号</td><td>标题</td><td>大图</td> </tr> <asp:Repeater ID="_usingList" runat="server"> <ItemTemplate> <tr> <td><input class="newsId-using" type="checkbox" name="newsId" value="<%#Eval("NewsId") %>" /></td> <td><%#Eval("RecordNum")%></td> <td><%#Eval("NewsTitle") %></td> <td style="padding:10px 0px 10px 10px;"> <a href='/Upload/Focus/<%# Path.GetFileNameWithoutExtension(Eval("ImgName").ToString())+"big"+Path.GetExtension(Eval("ImgName").ToString()) %>' target="_blank"> <img src='/Upload/Focus/<%# Path.GetFileNameWithoutExtension(Eval("ImgName").ToString())+"big"+Path.GetExtension(Eval("ImgName").ToString()) %>' /> </a> </td> </tr> </ItemTemplate> </asp:Repeater> </table> </form> </div> </td> </tr> </table>
public bool Save(string [] ids) { StringBuilder sb = new StringBuilder(); int index = 1; foreach (string id in ids) { sb.Append("update T_ADM_FocusPic set OrderNumber=" + index.ToString() + ",IsDisplay=1 where NewsId=@id" + index.ToString() + ";"); index += 1; } index = 1; SqlParameter[] pas = new SqlParameter[ids.Length]; foreach (string id in ids) { pas[index - 1] = new SqlParameter("@id" + index.ToString(), SqlDbType.Int, 4); pas[index - 1].Value = id; index += 1; } List<CommandInfo> infos = new List<CommandInfo>() { new CommandInfo(sb.ToString(), pas) }; if (DbPortalHelper.ExecuteSqlTran(infos) > 0) { return true; } return false; }