在DropDownList中选择多个值

时间:2018-10-14 07:02:30

标签: asp.net vb.net

我有一个下拉列表(SingleSelection),它从sql数据库中检索数据,我想将其更改为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

您的努力将不胜感激。

1 个答案:

答案 0 :(得分: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>