Changing the selected value of a drop down based on the selected value of another drop down in VB.Net
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
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!
精彩评论