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

发布于 2024-10-24 08:03:26 字数 1198 浏览 1 评论 0原文

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

这是我的代码:

    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

非常感谢任何帮助

I have a dropdown box which is used to select a user from a database. I am then populating a number of textboxes with the user information from the database. I want to populate a dropdown box, which holds the user's role, dependent on which user is selected from the first drop down box.

Here is my code:

    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

any help is greatly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-10-31 08:03:26

您必须通过在第一个选择下拉列表上进行回发,然后根据第一个选择下拉列表获取第二个选择的内容来完成此操作...

希望有所帮助!

You have to do this by doing a Post-back on the fist select drop down and then getting the content for the second one depending of the selection made on the first...

Hoped that helped!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文