【问题标题】:Select multiple value in DropDownList在 DropDownList 中选择多个值
【发布时间】:2018-10-14 16:30:27
【问题描述】:

我有一个从 sql 数据库中检索数据的下拉列表(SingleSelection),我想将其更改为 MultiSelection(选择多值),以下是我的代码。

ASP.NET

<asp:DropDownList ID="DrpGroup" runat="server" Width="250px" AutoPostBack="True">
</asp:DropDownList>

VB

Protected Sub DrpGroup_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DrpGroup.SelectedIndexChanged
    If (DrpGroup.SelectedValue.ToString.Trim.ToUpper <> "PLEASE SELECT...") Then
        Dim cnt_value As Integer = TDES.FindKey("Select Count(*) from dbo.VU_CUSTOMERBYGROUP WHERE upper(ltrim(rtrim(GROUP_NAME)))='" & DrpGroup.SelectedValue.ToString.Trim.ToUpper & "'")
        lblNumberCount.Visible = True
        lblNumberCount.Text = DrpGroup.SelectedValue.ToString.Trim.ToUpper & " has " & CStr(cnt_value) & " member(s). <br /> The cost for this SMS broadcast will be xxx" & CStr(cnt_value * 0.5)
    End If
    If (DrpGroup.SelectedValue.ToString.Trim.ToUpper = "PLEASE SELECT...") Then
        lblNumberCount.Visible = False
    End If
End Sub

您的努力将不胜感激。

【问题讨论】:

  • asp:DropDownList 将不直接支持多选。取而代之的是,您可以使用CheckBoxListListBox 控件。

标签: asp.net vb.net


【解决方案1】:

使用ListBox 而不是DropDownList

<asp:ListBox  runat="server" ID="multiSelect" SelectionMode="multiple" >
  <asp:ListItem Text="option1" Value="option1"></asp:ListItem>
  <asp:ListItem Text="option2" Value="option2"></asp:ListItem>
  <asp:ListItem Text="option3" Value="option3"></asp:ListItem>
</asp:ListBox>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-10
    • 2014-09-30
    • 2019-04-30
    • 1970-01-01
    • 1970-01-01
    • 2020-03-03
    相关资源
    最近更新 更多