列表框和javascript添加项目

byt*_*ave 1 javascript asp.net listbox

我有2个asp列表框控件和一个html输入按钮,并使用js我添加项目(以前从DB加载)从列表框A到B,它工作正常,但当我提交表单时,在列表框B后面的代码中做没有我添加的项目可访问.

我的想法是试图将往返保存到服务器并在客户端进行,但看起来它不起作用.

有任何想法吗?

非常感谢你的时间!

编辑

有代码

<asp:ListBox ID="lstBoxOrgs" runat="server" Height="117px"  Width="502px" SelectionMode="Multiple"></asp:ListBox>
<input type="button" value="Add" onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') "/>
Run Code Online (Sandbox Code Playgroud)

代码背后:

protected void AssignOrgs_Click(object sender, EventArgs e)
{
    foreach (ListItem orgItem in lstBoxUserRelOrgs.Items)
    {
        //Update database here...
    }

    //Commit updates to DB
    cdc.SubmitChanges();
}
Run Code Online (Sandbox Code Playgroud)

onclick="AddItems2Listbox('lstBoxOrgs', 'lstBoxUserRelOrgs') 是将lisbox A中的项目添加到列表框B的javascript函数.

谢谢

epa*_*llo 5

你有两个选择.第一个选项是跟踪隐藏变量中添加的选项并在服务器上读取.

第二个选项是在页面提交时选择所有选项,并使用Request.Form获取列表中选项的值.

您无法像在后端一样引用您的选择,因为viewstate不知道添加/删除了选项.