下拉查找值不起作用

时间:2017-03-17 02:52:08

标签: mysql asp.net vb.net modal-dialog dropdown

我目前在模式对话框中有2个下拉列表因此用于更新面板,1用于用户,另一个用于用户所属。

            <p class="text-justify">
                  <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                <ContentTemplate>
            <table class="table">
                <col width="150">
                <col width="800">
                <tr>
                    <td>Username</td>
                    <td>
                        <asp:DropDownList ID="ddlUpdateUsername" runat="server" class="form-control" OnSelectedIndexChanged="ddlUpdateUsername_SelectedIndexChanged" AutoPostBack="true">
                            <asp:ListItem> -- Select a user -- </asp:ListItem>
                        </asp:DropDownList>
                    </td>
                </tr>

                <tr>
                    <td>Group</td>
                    <td>
                        <asp:DropDownList ID="ddlUpdateGroup" runat="server" class="form-control">
                            <asp:ListItem> -- Select a group -- </asp:ListItem>
                            <asp:ListItem Value="Billing">Billing</asp:ListItem>
                            <asp:ListItem Value="Commercial">Commercial</asp:ListItem>
                            <asp:ListItem Value="Service">Service Assurance</asp:ListItem>
                        </asp:DropDownList>
                              </tr>
                    </ContentTemplate>
                </asp:UpdatePanel>

在后面的代码中,我有一个方法来获取用户数据下拉选择索引已更改。

    Protected Sub ddlUpdateUsername_SelectedIndexChanged(sender As Object, e As EventArgs)

        updateUserID = ddlUpdateUsername.SelectedValue
        getDetails(ddlUpdateUsername.SelectedValue)

        ddlUpdateGroup.Items.FindByValue(updateGroupID.Trim()).Selected = True

   End Sub

getDetails 方法如下。

    Public Sub getDetails(ByVal userID As String)

    Dim myConnection As MySqlConnection
    Dim myDataAdapter As MySqlDataAdapter
    Dim myDataset As DataSet

    Dim strSQL As String

    myConnection = New MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("for_Read").ConnectionString)

    myConnection.Close()
    myConnection.Open()

    strSQL = "SELECT `group_details`.`group_description` FROM `group_details` INNER JOIN `permission_details` ON `group_details`.`group_ID` = `permission_details`.`group_ID` WHERE `permission_details`.`user_ID` = '" & userID & "'"

    myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
    myDataset = New DataSet()
    myDataAdapter.Fill(myDataset, "permission_details")

    updateGroupID = myDataset.Tables("permission_details").Rows(0)(0).ToString()

End Sub

但是, FindByValue 无效。什么是错误的线索?

1 个答案:

答案 0 :(得分:0)

它总是适合我。试试这个

If Not ddlUpdateGroup.Items.FindByValue(updateGroupID.Trim()) Is Nothing Then

    ddlUpdateGroup.SelectedValue = ddlUpdateGroup.Items.FindByValue(updateGroupID.Trim()).Value

End If
  

示例:

     

enter image description here