I have an EDIT EMPLOYEE page. It contains a dropdown a user must select an employee from.
I have other dropdowns on the page, for example site, department, and position dropdowns.
The department, siten, and position dropdowns are populated from the database.
When user selects employee John Smith. I need the other dropdowns to show his site, department, and position.
So if John Smith's position is IT, I want that to be selected in the dropdown along with all other positions that were returned by the database.
How can I do this?
Here is my code so far:
Any help would be greatly appreciated.
Thanks,
Ninel
I have other dropdowns on the page, for example site, department, and position dropdowns.
The department, siten, and position dropdowns are populated from the database.
When user selects employee John Smith. I need the other dropdowns to show his site, department, and position.
So if John Smith's position is IT, I want that to be selected in the dropdown along with all other positions that were returned by the database.
How can I do this?
Here is my code so far:
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
If Request.Cookies.Count = 1 Then
Response.Redirect("login.aspx")
ElseIf Request.Cookies.Count = 2 Then
Dim sSQLEmployee As String
Dim oConn As SqlConnection
Dim oComm As SqlCommand
Dim sConn As String
Dim oReader As SqlDataReader
'Employee
sSQLEmployee = "SELECT sAgentId, rtrim(ltrim(slastname)) + ' ' + rtrim(ltrim(sfirstname)) as 'Name' From ememployee WHERE slastname <> ' ' ORDER BY slastname"
sConn = System.Configuration.ConfigurationSettings.AppSettings.Item("connString")
oConn = New SqlConnection(sConn)
oConn.Open()
oComm = New SqlCommand(sSQLEmployee, oConn)
oReader = oComm.ExecuteReader()
ddlEmployee.DataSource = oReader
ddlEmployee.DataBind()
ddlEmployee.Items.Insert(0, "SELECT")
ddlEmployee.Items(0).Value = 0
ddlEmployee.Items(0).Selected = True
oConn.Close()
End If
End If
End Sub
Private Sub ddlEmployee_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlEmployee.SelectedIndexChanged
sAgentId = ddlEmployee.SelectedValue
If sAgentId = "0" Then
lblResult.Text = "Please Select an Employee"
Else
Call PopulateDDLs(sAgentId)
End If
End Sub
Sub PopulateDDLs(ByVal sAgentId As String)
Dim oConn As SqlConnection
Dim oComm As SqlCommand
Dim oReader As SqlDataReader
Dim sSQLPayRollId As String
Dim sSQLEmployee As String
Dim sSQLAgentid As String
Dim sConn As String
Dim sErrorText As String
Dim sLastName As String
Dim sFirstName As String
Dim buspGetTextBoxValues As Boolean
Dim iPayRollId As String
Dim sSSN As String
Dim iMsPositionId As String
Dim iMsDepartmentId As String
Dim iMsSiteId As String
'AgentId
txtEmpId.Text = ddlEmployee.SelectedValue
Dim da As New SqlDataAdapter
Dim ds As DataSet = New DataSet
buspGetTextBoxValues = GetControlValues(sAgentId, sFirstName, sLastName, iPayRollId, sSSN, iMsPositionId, iMsDepartmentId, iMsSiteId, sErrorText)
txtLname.Text = Trim(sLastName)
txtFname.Text = Trim(sFirstName)
If iPayRollId = "0" Then
txtPayId.Text = ""
Else
txtPayId.Text = Trim(iPayRollId)
End If
txtSSN.Text = Trim(sSSN)
'Site
sSQLReport = "SELECT imsSiteId, sDescription FROM dbo.msSite"
sConn = System.Configuration.ConfigurationSettings.AppSettings.Item("connString")
oConn = New SqlConnection(sConn)
oConn.Open()
oComm = New SqlCommand(sSQLReport, oConn)
oReader = oComm.ExecuteReader()
ddlSite.DataSource = oReader
ddlSite.DataBind()
ddlSite.Items.Insert(0, "SELECT")
oConn.Close()
'Department
sSQLReport = "SELECT imsDepartmentId, sDescription FROM dbo.msDepartment"
sConn = System.Configuration.ConfigurationSettings.AppSettings.Item("connString")
oConn = New SqlConnection(sConn)
oConn.Open()
oComm = New SqlCommand(sSQLReport, oConn)
oReader = oComm.ExecuteReader()
ddlDept.DataSource = oReader
ddlDept.DataBind()
ddlDept.Items.Insert(0, "SELECT")
oConn.Close()
'Position
sSQLReport = "SELECT imsPositionId, sDescription FROM dbo.msPosition"
sConn = System.Configuration.ConfigurationSettings.AppSettings.Item("connString")
oConn = New SqlConnection(sConn)
oConn.Open()
oComm = New SqlCommand(sSQLReport, oConn)
oReader = oComm.ExecuteReader()
ddlPosition.DataSource = oReader
ddlPosition.DataBind()
ddlPosition.Items.Insert(0, "SELECT")
oConn.Close()
End Sub
Any help would be greatly appreciated.
Thanks,
Ninel