locked
Dropdownmenu SelectedValue.Contains RRS feed

  • Question

  • User810354248 posted

    In my asp.net+VB+Sql web i have a piece of code with IF condition as under. The DM goes for divisional manager

    If appttxt.SelectedValue.Contains("DM") Then
    chtxt.Text = "3"
    end if

    it works fine but we have more equal appointments as under Divisional Manager Operation, Facilitating, Sales etc. DM is common in this. But if an appointment with SODM (staff officer to DM )comes this is also selected in above code.

    DMO, DMF, DMS

    please help me

    Monday, December 25, 2017 2:02 AM

Answers

  • User-1716253493 posted

    Maybe like this

    If appttxt.SelectedValue.Equal("DMO") or appttxt.SelectedValue.Equal("DMF") or appttxt.SelectedValue.Equal("DMS") Then
       'do something
    Else
       If appttxt.SelectedValue.Contains("DM") Then
             chtxt.Text = "3"
       End If
    End If
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 25, 2017 2:28 AM
  • User-1838255255 posted

    Hi Baiju EP,

    According to your description, I make a sample based on your code, please check: 

    Sample Code:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem>SODM</asp:ListItem>
                    <asp:ListItem Selected="True">DMO</asp:ListItem>
                    <asp:ListItem>DMF</asp:ListItem>
                    <asp:ListItem>DMS</asp:ListItem>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    
     Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
            Dim value = DropDownList1.SelectedValue
            If value.Contains("DM") AndAlso value <> "DMO" AndAlso value <> "DMF" AndAlso value <> "DMS" Then
                Response.Write(value)
            End If
        End Sub

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 26, 2017 7:26 AM

All replies

  • User-1716253493 posted

    Maybe like this

    If appttxt.SelectedValue.Equal("DMO") or appttxt.SelectedValue.Equal("DMF") or appttxt.SelectedValue.Equal("DMS") Then
       'do something
    Else
       If appttxt.SelectedValue.Contains("DM") Then
             chtxt.Text = "3"
       End If
    End If
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 25, 2017 2:28 AM
  • User-1838255255 posted

    Hi Baiju EP,

    According to your description, I make a sample based on your code, please check: 

    Sample Code:

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                    <asp:ListItem>SODM</asp:ListItem>
                    <asp:ListItem Selected="True">DMO</asp:ListItem>
                    <asp:ListItem>DMF</asp:ListItem>
                    <asp:ListItem>DMS</asp:ListItem>
                </asp:DropDownList>
            </div>
        </form>
    </body>
    
     Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
            Dim value = DropDownList1.SelectedValue
            If value.Contains("DM") AndAlso value <> "DMO" AndAlso value <> "DMF" AndAlso value <> "DMS" Then
                Response.Write(value)
            End If
        End Sub

    Best Regards,

    Eric Du 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 26, 2017 7:26 AM