VB.Net 中根据另一个下拉列表的选定值更改下拉列表的选定值
我有一个下拉框,用于从数据库中选择用户。然后,我使用数据库中的用户信息填充多个文本框。我想填充一个下拉框,其中包含用户的角色,具体取决于从第一个下拉框中选择的用户。
这是我的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须通过在第一个选择下拉列表上进行回发,然后根据第一个选择下拉列表获取第二个选择的内容来完成此操作...
希望有所帮助!
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!