我现在把这头发拔了太久了。希望你们能帮帮忙。
我有一个表单,允许用户从“技能”列表中添加“我的个人技能”。
我使用jQuery完成了“加号按钮(+)”和减号按钮( - )代码,如下所示:
<script language="javascript" type="text/javascript">
function AddItSkills() {
var selectedOptions = jQuery('#<%=ListITProgramming.ClientID %> option:selected');
if (selectedOptions.length == 0) {
alert("Please select option to move.");
return false;
}
if (selectedOptions.length == 1) {
if (jQuery("#<%=ListMyITProgramming.ClientID %> option[value='" + selectedOptions.val() + "']").length > 0) {
}
else {
jQuery('#<%=ListMyITProgramming.ClientID %>').append(jQuery(selectedOptions).clone());
}
}
else if (selectedOptions.length > 1) { jQuery(selectedOptions).each(function () { if (jQuery("#<%=ListMyITProgramming.ClientID %> option[value='" + this.value + "']").length > 0) { } else { jQuery('#<%=ListMyITProgramming.ClientID %>').append(jQuery(this).clone()); } }); }
jQuery(selectedOptions).remove();
return false;
}
function RemoveITSkills() {
var selectedOptions = jQuery('#<%=ListMyITProgramming.ClientID %> option:selected');
if (selectedOptions.length == 0) {
alert("Please select option to move.");
return false;
}
if (selectedOptions.length == 1) {
if (jQuery("#<%=ListITProgramming.ClientID %> option[value='" + selectedOptions.val() + "']").length > 0) {
}
else {
jQuery('#<%=ListITProgramming.ClientID %>').append(jQuery(selectedOptions).clone());
}
}
else if (selectedOptions.length > 1) { jQuery(selectedOptions).each(function () { if (jQuery("#<%=ListITProgramming.ClientID %> option[value='" + this.value + "']").length > 0) { } else { jQuery('#<%=ListITProgramming.ClientID %>').append(jQuery(this).clone()); } }); }
jQuery(selectedOptions).remove();
return false;
}
在这种情况下,“技能”与数据库有关,“我的个人技能”是空的。用户将“技能”添加到“我的个人技能”中,然后单击“保存”按钮。
在c#代码后面,我无法从“我的个人技能”中获取项目列表,因为它们是通过jQuery添加的。
你能否向我提供指导,以便在c#代码中获得“我的个人技能”项目?
答案 0 :(得分:1)
隐藏的田地将是这里的银子弹。
步骤1。在页面中添加一个asp隐藏字段,可以说hf1是它的id。
步骤2。将clientclick事件添加到保存按钮
step3.in客户端clickevent获取所有个人技能并使用逗号或“|”将它们组成一个字符串
步骤4。将hf1值设置为step3生成的字符串,然后发布。
步骤5.在服务器端获取hf1的值,该值与第3步中生成的字符串相同。
步骤6。反序列化它并//做你想做的任何事情。
希望这个帮助