我有两个asp下拉列表..基于两个下拉列表中选择的值,它将动态生成两个无序列表,我在其中实现了Jquery Sortable连接列表..第一个列表包含一些默认值..我需要拖放第二个列表所需的值......它应该防止添加重复的条目..
我在下面粘贴我的代码......请检查并为我提供解决方案:
这是两个下拉列表的 aspx 代码:
<form id="form1" runat="server">
Application <asp:DropDownList ID="ApplicationList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="FetchRoleFromApplication" >
</asp:DropDownList>
Role <asp:DropDownList ID="RoleName" runat="server" onchange="javascript:ShowSortable();" >
</asp:DropDownList>
<ul id="sortable1" class="connectedSortable" runat="server" style="display:none">
</ul>
<ul id="sortable2" class="connectedSortable" style="display:none" runat="server" >
</ul>
</form>
第一个 ul 列表是独立的,因此它的值被加载到 codebehind(pageload) 中,如下所示:
HtmlGenericControl li;
JavaScriptSerializer objJSSerializer = new JavaScriptSerializer();
foreach (FetchUserGroup_Result objectItem in Allusergroup)
{
li = new HtmlGenericControl("li");
li.ID = objectItem.group_id.ToString();
li.Attributes.Add("class", "ui-state-default");
li.InnerText = objectItem.group_name;
sortable1.Controls.Add(li);
}
第二个 ul 列表值由这样的 ajax 调用加载...
function ShowSortable() {
$('#sortable1').show();
var postJSONData = JSON.stringify({ ApplicationId: $('#applnhdnname').val(), RoleName: $('#RoleName').val() });
$.ajax({
type: 'POST',
data: postJSONData,
url: 'UserManagementService.svc/GetUserGroupsForApplicationRole',
dataType: 'json',
async: false,
contentType: 'application/json; charset=utf-8',
success: function success(response) {
$("#sortable2").append(response.d);
$('#sortable2').show();
},
error: SessionExpiryHandler
});
}
对应的 wcf 服务是这样的:
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
public string GetUserGroupsForApplicationRole(string ApplicationId, string RoleName)
{
User user = new User();
JavaScriptSerializer objJSSerializer = new JavaScriptSerializer();
List<GetUserGroupForApplicationRole_Result> usergroup;
usergroup = user.GetUserGroupForApplicationRole(ApplicationId, RoleName);
string sample = string.Empty;
foreach (GetUserGroupForApplicationRole_Result objectItem in usergroup)
{
sample += "<li id= "+objectItem.group_id+ " class='ui-state-highlight'>";
sample += objectItem.group_name;
sample+="</li>";
}
return sample;
}
如何避免在此重复值...请帮帮我..
提前致谢..