Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populate controls on page based on what was chosen from dropdown

Status
Not open for further replies.

ninelgorb

Programmer
Mar 7, 2005
111
US
I have a web page that edits an employee's information.

The user first must select an employee from a dropdown. Based on the employee chosen I need all other controls on that page to populate with that employee's information.

Does anyone know how to do this? Is this done with vb.net or asp.net?

Any help would be greatly appreciated.

Thanks,
Ninel
 
You can do it with either. First select the employee and grab the value of the dropdown in the SelectedIndexChanged event. Then run a sql statment or stored procedure to retrive the employee info into a dataset. Then you can bind the values to contorls(textboxes, datagrid..etc)
 
Would it look something like this?
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 iEmEmployeeId, 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   
   Dim sEmployee as string

   sEmployee = ddlEmployee.SelectedItem.Text
End Sub

I'm sure this is wrong, but maybe close? I'm debgging this code and I can't seem to jump into this event.

What am I doing wrong?

Thanks,
Ninel
 
The one this I see is that sEmployee must be declared at page level, otherwise you will get an error.

Do you mean you never hit the ddlEmployee_SelectedIndexChanged event? Make sure autopostback is set to true.

Also, you have to remove your select and fill code from the IF Not is post back, otherwise it will not fire when the dropdown is changed. It will only fire once on the initial page load
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top