none
Como carregar o DropDownList RRS feed

  • Pergunta

  • Alguma sugestão para carregar o DropDownList5_empresa ?

    CAMADA DATA

        

    Public Class ClassData1_SelReader
        Public Shared Function sel(ByVal comando As String, ByVal param As ArrayList) As DataTable
            Dim objDR As SqlDataReader
            Dim data_DT As DataTable = New DataTable()
            Using CN As SqlConnection = New SqlConnection()
                Try
                    CN.ConnectionString = My.Settings.cn1
                    Dim com As SqlCommand = New SqlCommand()
                    com.CommandText = comando
                    com.CommandType = CommandType.Text
                    Dim c As Integer = 0

                    For Each item In param
                        c += 1
                        com.Parameters.Add(String.Format("@Par{0}", c), GetDBType(item.GetType())).Value = item
                    Next
                    com.Connection = CN
                    CN.Open()
                    objDR = com.ExecuteReader(CommandBehavior.CloseConnection)
                    data_DT.Load(objDR)
                    CN.Close()
                    Return data_DT
                Catch ex As Exception
                    '...erros                
                End Try
                Return data_DT
            End Using
        End Function

    CAMADA MODEL

    Public Class ClassModel5_Empresa
        Dim a_id_pj As Integer
        Dim a_nome_empresarial As String

        Public Sub empresa(ByVal id_pj, ByVal nome_empresarial)

            Dim Model_DataTable As DataTable
            Dim comando As String
            comando = "SELECT id_pj,nome_empresarial FROM tb_cad_pj WHERE id_pj=@Par1,nome_empresarial=@Par2 ORDER nome_empresarial"
            Dim param As ArrayList = New ArrayList()
            param.Add(nome_empresarial)
            param.Add(id_pj)
            Model_DataTable = ClassData1_SelReader.sel(comando, param)
            For Each linha In Model_DataTable.Rows
                a_id_pj = id_pj
                a_nome_empresarial = nome_empresarial           
            Next

        End Sub

        Public Property id_pj() As Integer
            Get
                Return a_id_pj
            End Get
            Set(ByVal value As Integer)
                a_id_pj = value
            End Set
        End Property

        Public Property nome_empresarial() As String
            Get
                Return a_nome_empresarial
            End Get
            Set(ByVal value As String)
                a_nome_empresarial = value
            End Set
        End Property

    CAMADA VIEW

    Private Sub Carga_Drop_Empresa()
            Dim Empresa As New ClassModel5_Empresa()
            DropDownList5_empresa.Items.Clear()
            DropDownList5_empresa.DataSource = .........
            DropDownList5_empresa.DataTextField = Empresa.nome_empresarial
            DropDownList5_empresa.DataValueField = Empresa.id_pj
            DropDownList5_empresa.DataBind()
    End Sub

    terça-feira, 14 de maio de 2013 19:46

Respostas

Todas as Respostas