Dudas de Programacion » Dot Net » ASP .NET

Necesito Ayuda con DropDownList en aspx

(1 post)
  • Started 3 months ago by meline

Tags:

No tags yet.

  1. Tendo un dropdownlist k me muestra nombres de departamentos de trabajo.
    y necesito k al momento de seleccionar un departamento en otro dropdownlist me muestra el nombre de los empleados que hay solo en ese departamento seleccionado aqui le pongo parte del codigo que estoy realizando, espero que puedan ayudarme. de ante mano gracias
    ESTE ES EL QUE MUESTRA EL NOM DE LOS DEPARTAMENTOS EN ASP:
    <asp:SqlDataSource ID="dsSql2" runat="server" ConnectionString="<%$ ConnectionStrings:RHABCD %>"
    SelectCommand="Select * from tblCentros"></asp:SqlDataSource>
    <asp:DropDownList ID="cbnomdepto" runat="server" class="cajas_text4" DataSourceID="dsSql2"
    DataTextField="Nomdepto" DataValueField="Centro"
    OnSelectedIndexChanged="ActualizarDeptos" AutoPostBack="true" Height="16px" Width="273px">
    </asp:DropDownList>

    Y EN VISUAL BASIC ESTO ES LO K ESTOY HACIENDO PARA QUE AL SELECCIONAR EL DEPARTMENTO ME MUESTRE EL NOMBRE DE LOS EMPLEADOS:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Not Page.IsPostBack Then
    cbDesemp.Items.Add("Excelente")
    cbDesemp.Items.Add("Muy buena")
    cbDesemp.Items.Add("Buena")
    cbDesemp.Items.Add("Regular")
    cbDesemp.Items.Add("Mala")
    cbDesemp.Items.Add("Pésima")
    // aqui estoy utilizando una tabla en memoria:
    Dim tbxPercepciones As New DataTable
    tbxPercepciones.Columns.Add("idPercepcion", GetType(Int16))
    tbxPercepciones.Columns.Add("Percepcion", GetType(String))
    tbxPercepciones.Columns.Add("Rfc", GetType(String))

    'tbxEmpleados As New DataTable
    tbxEmpleados.Columns.Add("Rfc", GetType(String))
    tbxEmpleados.Columns.Add("Nombre", GetType(String))

    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    Dim dr As SqlDataReader
    'declaring the objects
    myConnection = New SqlConnection("server=serversql;uid=produccion;pwd=qpaso@produccion;database=rh_abcd")
    Try
    myConnection.Open()

    'opening the connection
    myCommand = New SqlCommand("Select * from tblEvaluacionP", myConnection)
    'executing the command and assigning it to connection
    dr = myCommand.ExecuteReader()
    While dr.Read()
    'reading from the datareader
    tbxPercepciones.Rows.Add(dr("idEvaluacionP"), dr("NombreEvaluacion"), vbNull)
    End While
    dr.Close()

    'opening the connection
    'myCommand = New SqlCommand("Select Rfc, Nombre from Andreus where centro='050005005053'", myConnection)
    myCommand = New SqlCommand("Select Rfc, Nombre from Andreus where centro='nomdepto'", myConnection)
    'executing the command and assigning it to connection
    dr = myCommand.ExecuteReader()

    tbxEmpleados.Rows.Add(vbNull, "No Seleccionado")
    cbnomdepto.Text = "nomdepto"
    While dr.Read()
    'reading from the datareader
    tbxEmpleados.Rows.Add(dr("Rfc"), dr("Nombre"))
    End While
    dr.Close()

    myConnection.Close()
    Catch
    End Try

    gvPercepcion.DataSource = tbxPercepciones
    gvPercepcion.DataBind()

    End If

    End Sub

    Protected Sub ActualizarDeptos(ByVal sender As Object, ByVal e As System.EventArgs) Handles cbnomdepto.SelectedIndexChanged
    Dim cbEmpleados As DropDownList
    Dim myConnection As SqlConnection
    Dim myCommand As SqlCommand
    myConnection = New SqlConnection("server=serversql;uid=produccion;pwd=qpaso@produccion;database=rh_abcd")
    Try
    myConnection.Open()
    Dim dr As SqlDataReader
    myCommand = New SqlCommand("Select Rfc, Nombre from Andreus where nomdepto=@nomdepto", myConnection)
    'executing the command and assigning it to connection
    dr = myCommand.ExecuteReader()
    cbnomdepto.DataValueField = "nomdepto"
    While dr.Read()
    'reading from the datareader
    cbEmpleados = cbnomdepto
    cbEmpleados.Items.Add(" No Seleccionado")
    cbEmpleados.SelectedIndex = cbEmpleados.Items.Count - 1
    cbEmpleados.SelectedItem.Value = "nomdepto"
    End While
    dr.Close()

    myConnection.Close()
    Catch
    End Try

    cbnomdepto.DataBind()
    End Sub

    Protected Sub gvPercepcion_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    Dim ddl As DropDownList

    If (Not IsPostBack) Then
    If (e.Row.RowType = DataControlRowType.DataRow) Then
    ddl = e.Row.FindControl("cbEmpleados")
    ddl.DataSource = tbxEmpleados
    ddl.DataBind()
    End If
    End If
    End Sub

    que es lo k estoy haciendo mal alguien k me ayude x favor...

    Posted 3 months ago #



Reply

You must log in to post.

606 posts in 271 topics over 19 months by 237 of 398 members. Latest: ripersdick, martiro12, asugom

Acerca de...

Dudas de Programación es una Web, dentro del proyecto aulambra.com que nace con la idea de propocionar un foro de consultas sobre diferentes temas de programación. Orientado a ayudar a los internautas hispano-hablantes en Internet.

Ir al Blog de Linea de Código

Otras Webs