根据VB.Net中另一个下拉列表的选定值更改下拉列表的选定值

时间:2011-03-19 15:26:48

标签: asp.net vb.net drop-down-menu webforms

我有一个下拉框,用于从数据库中选择用户。然后,我将使用数据库中的用户信息填充许多文本框。我想填充一个下拉框,其中包含用户的角色,具体取决于从第一个下拉框中选择的用户。

这是我的代码:

    Dim currentUser As String = editUserDropDown.SelectedValue
    Dim getUserDetails = "Select aspnet_Users.UserName, aspnet_Roles.RoleName, [User Details].EmployeeName, [User Details].EmployeeAddress, [User Details].PersonalEmailAddress FROM aspnet_Users INNER JOIN [User Details] ON aspnet_Users.UserId = [User Details].UserId CROSS JOIN aspnet_Roles WHERE (aspnet_Users.UserName = '" & currentUser & "')"
    Dim getUserDetailsCmd As New SqlClient.SqlDataAdapter(getUserDetails, DBConn)
    Dim getUserDetailsDS As New DataSet
    getUserDetailsCmd.Fill(getUserDetailsDS)

    Dim username = getUserDetailsDS.Tables(0).Rows(0).Item(0)
    Dim roleName = getUserDetailsDS.Tables(0).Rows(0).Item(1)
    Dim name = getUserDetailsDS.Tables(0).Rows(0).Item(2)
    Dim address = getUserDetailsDS.Tables(0).Rows(0).Item(3)
    Dim email = getUserDetailsDS.Tables(0).Rows(0).Item(4)


    userNameTxt.Text = username

    roleSelect.SelectedValue = roleName

    nameTxt.Text = name
    addressTxt.Text = address.Trim()
    emailTxt.Text = email

非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

你必须通过在第一个选择下拉列表上进行回传,然后根据第一个选择的内容获取第二个内容...

希望有所帮助!