我的aspx页面中有10个列表框用于所有10个列表框相同的功能用于某些按钮我想将列表框数据添加到网格中你能帮我看看下面显示的java脚本代码
function MoveItem(ctrlSource, ctrlTarget) {
var Source = document.getElementById(ctrlSource);
var Target = document.getElementById(ctrlTarget);
if ((Source != null) && (Target != null)) {
while ( Source.options.selectedIndex >= 0 ) {
var newOption = new Option(); // Create a new instance of ListItem
newOption.text = Source.options[Source.options.selectedIndex].text;
newOption.value = Source.options[Source.options.selectedIndex].value;
Target.options[Target.length] = newOption; //Append the item in Target
Source.remove(Source.options.selectedIndex); //Remove the item from Source
}
}
}
我尝试使用javascript以上代码在列表框之间使用html输入按钮问题移动项目当我尝试保存listbox.items.count给0时,任何人都可以告诉我为什么会发生这种情况,并且当发回时发生列表框项目丢失。
答案 0 :(得分:2)
尊敬的,
这是正常的,任何改变客户端到列表框的东西都不会反映在服务器端。
您可以在按钮上添加onclientclick事件并从列表框客户端读取项目并使用AJAX保存它们,或者您可以从列表框客户端读取项目并将它们作为字符串放在隐藏字段中,您可以阅读隐藏字段服务器端的值。
您可以从客户端读取所有项目,并以您自己的格式将其格式化为字符串。
然后在页面上添加一个asp隐藏字段,客户端将你拥有的字符串放在隐藏字段值属性中。
现在您可以从服务器端的onclick事件访问该字符串,并提取列表框中的项目。