无法检索列表框项值 ASP.NET

Unable to Retrieve ListBox Item Value ASP.NET

我的 ListFolder 列表框控件返回 0 项。

我已经放入了一个 testLB 列表框控件进行测试,可以检索项目。

下面是代码片段。

前端:

//Returned 0
<div class="tab-content">
    <div id="sectionC" class="tab-pane fade in active">
        <asp:ListBox runat="server" ID="listFolder" CssClass="fileHeight" Style="width: 100%;" SelectionMode="Single" ClientIDMode="Static" onclick="onListFolderClick(); ">
        </asp:ListBox>
    </div>
</div>

//Returned 1
<asp:ListBox ID="testLB" class="chosen" runat="server" Width="450px" Height="20px" SelectionMode="Single" ClientIDMode="Static">
    <asp:ListItem>item1</asp:ListItem>  
</asp:ListBox>

页面加载时:

//Returned 0
Log.LogDebug("listFolder.Items.Count:" + listFolder.Items.Count, Location);

//Returned 1 
Log.LogDebug("testLB.Items.Count: " + testLB.Items.Count, Location);

页面UI截图:

Headers分别选在左控件All Headers上,added/removed分别选在右控件Selected HeaderslistFolderslb控件上。

最后,单击 Generate Report 按钮,将检索 listFolder lb 控件中的所有值。

我是否需要包含一个容器来存储物品,例如<asp:ListItem> 能够检索 lb 值?

如有任何帮助,我们将不胜感激!

适合你必须将 SelectionMode 更改为 Multiple

<asp:ListBox runat="server" ID="listFolder" CssClass="fileHeight" Style="width: 100%;" SelectionMode="Multiple" ClientIDMode="Static" onclick="onListFolderClick(); ">
        </asp:ListBox>

为 select listFolder 中的所有项目创建 javascript 方法:

function SelectAllItems() {
    $("#listFolder").each(function() { 
        $("#listFolder option").attr("selected", "selected"); 
    }); 

    $("#listFolder").focus();
}

在“生成报告”按钮上调用 SelectAllItems

<input type="submit" value="Generate Report" onsubmit="SelectAllItems()" />