none
carregar várias dropdowlist! RRS feed

  • Pergunta

  • PessoALL!!!!

    Estou com uma dúvida, meu form tem várias dropdownlist e estou acessando desta forma.

    Gostaria de saber como seguir essa lógica para implementar um NOVO dropdownlist diferente?

    Partial Class Maquina
        Inherits System.Web.UI.Page
        '------------------------------------------------------------------------------'

        ' pego a connstr
        Dim strConnStringNew As String = ConfigurationManager.ConnectionStrings.Item("SqlConnectionStringNew").ToString()
        Dim oConn As New SqlConnection(strConnStringNew)

        ' variaveis objetos
        Dim oStr As String
        Dim myInsert As String
        Dim oCmd As SqlCommand

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click

            If txtMaquina.Text <> String.Empty And txtMaquinaIP.Text <> String.Empty And txtColaborador.Text <> String.Empty And txtMAC.Text <> String.Empty Then

                Try
                    oConn.Open()

                    myInsert = "INSERT INTO maquina" & _
                    "(id_departamento,nome_maquina,ip,colaborador,mac) VALUES" & _
                    "(@id_departamento,@nome_maquina,@ip,@colaborador,@mac)"

                    oCmd = New SqlCommand(myInsert, oConn)

                    oCmd.Parameters.Add(New SqlParameter("@nome_maquina", txtMaquina.Text))
                    oCmd.Parameters.Add(New SqlParameter("@ip", txtMaquinaIP.Text))
                    oCmd.Parameters.Add(New SqlParameter("@colaborador", txtColaborador.Text))
                    oCmd.Parameters.Add(New SqlParameter("@mac", txtMAC.Text))

                    oCmd.Parameters.AddWithValue("@id_departamento", ddlDepartamento.SelectedItem.Value)

                    oCmd.ExecuteNonQuery()
                    oConn.Close()

                    'Response.Redirect("Exibir.aspx")
                Catch ex As Exception
                    lblMsg.Text = ex.Message
                End Try

            End If

        End Sub

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

            ' Carregando os dados da base na combobox
            Using oConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SqlConnectionStringNew").ConnectionString)
                oConn.Open()
                oStr = "SELECT id_departamento, nome_departamento FROM departamento"
                oCmd = New SqlCommand(oStr, oConn)

                With Me.ddlDepartamento
                    .DataSource = oCmd.ExecuteReader()
                    .DataTextField = "nome_departamento"
                    .DataValueField = "id_departamento"
                    .DataBind()
                End With
            End Using
        End Sub

    End Class


    Missão Crítica

    terça-feira, 4 de dezembro de 2012 11:56