0
我正在嘗試使用此jquery對中繼器行進行排序。但我無法保存排序項目。請幫幫我 。如何保存數據庫以及在.aspx頁面中排序預先感謝您嘗試使用此jQuery對中繼器行進行排序
<script language="javascript" type="text/javascript">
$("#defaultList").sortable();
$(document).ready(function() {
$("#defaultList").sortable(
{
update: function (ev, ui) {
var result = $('#defaultList').sortable('toArray');
updateSequenceNumber(result);
}
}
);
});
function updateSequenceNumber(items) {
var originalIdAndSequenceNumber = '';
var index = 0;
for (i = 0; i <= items.length - 1; i++) {
if (items[i].length == 0)
continue;
var item = $('#' + items[i])[0];
originalIdAndSequenceNumber += item.attributes["originalId"].nodeValue + ":" + index.toString();
originalIdAndSequenceNumber += "|";
index = index + 1;
}
persistPositionUsingAjax(originalIdAndSequenceNumber);
}
function persistPositionUsingAjax(originalIdAndSequenceNumber) {
$.ajax(
{
type: "POST",
dataType: "text",
url: "AjaxService.asmx/UpdateSequenceNumber",
data: "s=" + originalIdAndSequenceNumber,
success: function (response) {
}
}
);
}
我的AJAX方法:
[WebMethod]
public string UpdateSequenceNumber(string s)
{
s = s.TrimEnd('|');
string updateQuery = @"update dnn_Table_1 set SortId = {0}
where ImageId = {1}";
StringBuilder sb = new StringBuilder();
string[] originalIdAndSeqNumberArray = s.Split('|');
foreach (var originalIdAndSeqNumberCombined in originalIdAndSeqNumberArray)
{
var tempArray = originalIdAndSeqNumberCombined.Split(':');
int originalId = Convert.ToInt32(tempArray[0]);
int sequenceNumber = Convert.ToInt32(tempArray[1]);
sb.Append(String.Format(updateQuery, sequenceNumber, originalId));
sb.Append(System.Environment.NewLine);
}
UpdateInDatabase(sb.ToString());
return "Hello World";
}
private void UpdateInDatabase(string updateQuery)
{
SqlDataProvider sqd = new SqlDataProvider();
string ConnectionString = sqd.ConnectionString;
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand command = new SqlCommand(updateQuery, conn);
command.CommandText = updateQuery;
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
http://highoncoding.com/Articles/513_Pimp_Up_List_Sorting_Using_JQuery.aspx。我參考這個網站。請幫幫我。 – user1240045 2012-03-20 08:33:03
doh我沒有看到sb.Append(System.Environment.NewLine);位,我在想MySql。 剛剛閱讀你提到的文章。看起來應該可以工作,但是ajax代碼的實際響應是什麼?用螢火蟲或小提琴或類似的東西檢查。也許你的連接有問題。 – 2012-03-20 08:44:39
您聲明#defaultList可排序兩次。刪除第一個。另外,在ajax成功函數中,輸入alert(response); – 2012-03-20 08:54:50