gpt4 book ai didi

c# - 使用javascript将值从一个列表框移动到另一个列表框,然后使用c#读取值

转载 作者:数据小太阳 更新时间:2023-10-29 05:27:11 26 4
gpt4 key购买 nike

我有两个列表框(列表框 1 和列表框 2)。我使用以下 javscript 代码将值从一个列表框移动到另一个列表框。

 <script language="javascript" type="text/javascript">

function fnMoveItems(lstbxFrom,lstbxTo)
{
var varFromBox = document.all(lstbxFrom);
var varToBox = document.all(lstbxTo);
if ((varFromBox != null) && (varToBox != null))
{
if(varFromBox.length < 1)
{
alert('There are no items in the source ListBox');
return false;
}
if(varFromBox.options.selectedIndex == -1) // when no Item is selected the index will be -1

{
alert('Please select an Item to move');
return false;
}
while ( varFromBox.options.selectedIndex >= 0 )
{
var newOption = new Option(); // Create a new instance of ListItem

newOption.text = varFromBox.options[varFromBox.options.selectedIndex].text;
newOption.value = varFromBox.options[varFromBox.options.selectedIndex].value;
varToBox.options[varToBox.length] = newOption; //Append the item in Target Listbox

varFromBox.remove(varFromBox.options.selectedIndex); //Remove the item from Source Listbox

}
}
return false;
}
</script>

此代码将值从一个列表框移动到另一个列表框,但实际上当我尝试读取第二个列表框值时,一个值被复制到哪个列表框,我无法读取这些值。当我检查它显示 ListBox2.Items.Count 是 0

最佳答案

正如 Amar Palsapure 在评论中所述,如果您不进行一些黑客攻击(将值添加到隐藏字段等,请查看 here),使用 javascript 在客户端进行的更改不会反射(reflect)在服务器端,因此您不会能够看到服务器端的变化。我假设行 ListBox2.Items.Count 是服务器端。

如果您执行 ajax 请求并在更新面板中在服务器端执行,这对您来说会更好、更容易。

关于c# - 使用javascript将值从一个列表框移动到另一个列表框,然后使用c#读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8788656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com