【问题标题】:asp.net getting list of items selectedasp.net 获取所选项目的列表
【发布时间】:2011-09-16 17:08:52
【问题描述】:

我有一个组合框:

<select size="8" multiple="true" >
                <optgroup label="Europe">
                    <option>United Kingdom</option>
                    <option>Luxembourg</option>
                </optgroup>    
                <optgroup label="Asia">
                    <option>India</option>
                    <option>Dubai</option>
                </optgroup>
            </select>

我想知道如何返回到 asp.net 应用程序,用户选择了哪些条目?

【问题讨论】:

    标签: asp.net html


    【解决方案1】:

    开发人员为此创建了一个服务器端控件:http://weblogs.asp.net/jeff/archive/2006/12/27/dropdownlist-with-optgroup.aspx

    尝试添加 runat="server" 看看它会给你什么。您应该能够从服务器访问它的一些属性,但我不确定这一切如何与选项组一起使用。

    作为最后的手段,如果必须,创建一个&lt;asp:HiddenField /&gt; 控件并使用 JS 将选择的内容存储在那里。

    HTH。

    【讨论】:

    • 对于这一行:ListItem item = this.Items[i];我收到此错误:错误 48 无法将类型“对象”隐式转换为“System.Web.UI.WebControls.ListItem”。存在显式转换(您是否缺少演员表?) C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\lomdb\EnterData\DataEntry\WebForm1.aspx.cs 61 37 EnterData
    • 对于这一行 :if (selected) { this.VerifyMultiSelect();我收到此错误:错误 49“EnterData.DataEntry.WebForm1”不包含“VerifyMultiSelect”的定义,并且没有扩展方法“VerifyMultiSelect”接受“EnterData.DataEntry.WebForm1”类型的第一个参数(是您缺少 using 指令或程序集引用?) C:\Documents and Settings\agordon\My Documents\Visual Studio 2008\Projects\l
    • 我提供的链接,你把这个方法贴在页面类上了吗?这种方法是自定义控件。创建一个从下拉列表继承的新类,并将此方法放在那里。
    • 非常感谢。你能告诉我如何声明这种新型下拉菜单吗?我能够没有错误,现在我在这一点上 ListItem item = new ListItem("Group1", String.Empty); item.Attributes["optgroup"] = "optgroup"; myDropDown.Items.Add(item);
    • 对不起,这是一个下拉列表,我需要一个列表框或组合框
    猜你喜欢
    • 2011-06-08
    • 1970-01-01
    • 2014-03-19
    • 2023-03-29
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多