【发布时间】:2012-02-21 17:00:47
【问题描述】:
我已经 5 天尝试使用 asp.net c# 功能进行 jquery 拖放。
我有两个 asp 列表视图一个包含朋友列表,第二个是组容器。我要做的就是当用户从列表视图中拖动行项目并放在组列表视图中时,我想将其写入 sql server 数据表中。
我已经让 jquery 拖放它的工作良好,然后让 asp Web 服务即时使用 javascript 调用它并发送拖动的用户名。
我的网络服务是静态方法,当然不能访问组列表视图来更新它。 然后我尝试调用我的非静态方法,该方法从数据表中获取数据,然后绑定我的组的光照视图。
我像这样调用那个函数
GamerProfile gp = new GamerProfile();
GetClanData();
GamerProfile 是我的网络表单
public partial class GamerProfile : System.Web.UI.Page
GetClanData 在这条线上抛出错误Object reference not set to an instance of an object. dlClan.DataSource = _ClandCollection; 我知道它的发生,因为我创建了新类,然后调用了GetClanData();
是否可以在不创建新的情况下调用 GetClanData?
有什么办法吗?
我可以从 javascript 添加行到我的列表视图吗? 或者提出一些调用 GetClanData(non static) 方法的请求?
如果我试图用困难的方式做到这一点,请建议更简单的解决方案。
谢谢。对不起我的英语不好
这是我的整个 .js 文件
function SendUserToC(user) {
var result = PageMethods.AddUserToClan(user, OnSucceeded, OnFailed);
}
function OnSucceeded(result, userContext, methodName) {
if (result.indexOf("Warning") != -1) {
alert(result);
}
}
function OnFailed(error, userContext, methodName) {
}
$(document).ready(function () {
var UserCount = 0;
var UsersList = [];
$(".dragable").draggable({
helper: 'clone',
revert: true,
start: function () {
}
});
$("#clan_drop").droppable({
accept: ".dragable",
drop: function (ev, ui) {
UserCount++;
if (UserCount > 10) {
alert("You cannot add more users. Maximum quantity of gamers in one clan is 10");
} else {
$("#drag_here_container").css("display", "none");
var droppedItem = $(ui.draggable).clone();
$(this).append(droppedItem);
var user = $.trim($(this).find('.friend_user_name').text());
$('.dragable:last').remove();
SendUserToC(user);
}
}
});
});
【问题讨论】:
-
只是一个随机链接codeproject.com/Articles/24123/…
标签: c# javascript jquery asp.net ajax