Welcome Guest Search | Active Topics | Sign In | Register

Repopulate Grid Options
FCruz
Posted: Monday, July 5, 2010 11:39:16 AM
Rank: Member
Groups: Member

Joined: 6/4/2010
Posts: 16
Hi,

Actually I've a grid, this is binding whit a DataSet, the question is how I can to use the sorting property ?

I emphasize code important between label with [bFCruz].

The code is next.

Code: Visual Basic.NET
Private Sub obtenercargos()
            Dim objSN As New snLsenet.sn_clsPersona
            Dim objSNCP As New snLsenet.sn_clsConsultaF
            Dim objXml As System.Xml.XmlDocument
            Dim objDs As Data.DataSet
            Dim intFgStatus As Integer
            Dim intOrden As Integer
            Dim intRdbCveCliente As Integer = 0
            Dim intRdbRFC As Integer = 0
            Dim intrdbRazonSocial As Integer = 0
            Dim intCveCliente As Integer = 0
            Dim strRFC As String = ""
            Dim strRazonSocial As String = ""
            Dim strErr As String = ""
            Dim strUrl As String = ""
            Dim sUrl As New StringBuilder
            Dim strFecIni, strFecFin As String
            Dim strContrato As String = ""
            Dim dsaux As New Data.DataSet
            Dim aux As New snLsenet.sn_clsContratoPropuesta
            strMensaje = ""
            intFgStatus = -1
            intOrden = 2
            lblMensaje.Text = ""

            cmbContrato.Visible = False
            txtContrato.Style.Add("display", "inline")
            cmbMoneda.Enabled = True
            panTotal.Visible = False

            If Not rdbContrato.Checked And Not rdbCve.Checked And Not rdbNom.Checked And Not rdbRFC.Checked Then
                MensajeError(Me, "Debe seleccionar una opción de búsqueda")
                Me.hdnErrorMsg.Value = "Debe seleccionar una opción de búsqueda"
            End If

            If txtFechaValorInicio.Text.Trim.Length > 0 And txtFechaValorfin.Text.Trim.Length > 0 Then
                ''If txtFechaValorInicio.SelectedDateString.Trim.Length > 0 And txtFechaValorfin.SelectedDateString.Trim.Length > 0 Then
                If Not IsDate(txtFechaValorInicio.Text) Then
                    ''If Not IsDate(txtFechaValorInicio.SelectedDateString) Then
                    MensajeError(Me, "El dato introducido en el campo Fecha inicial no es valido")
                    Me.hdnErrorMsg.Value = "El dato introducido en el campo Fecha Inicial no es válido"
                    Exit Sub
                End If
                If Not IsDate(txtFechaValorfin.Text) Then
                    ''If Not IsDate(txtFechaValorfin.SelectedDateString) Then
                    MensajeError(Me, "El dato introducido en el campo Fecha final no es valido")
                    Me.hdnErrorMsg.Value = "El dato introducido en el campo Fecha Final no es válido"
                    Exit Sub
                End If

                If Date.Compare(CDate(txtFechaValorInicio.Text), CDate(txtFechaValorfin.Text)) > 0 Then
                    ''If Date.Compare(CDate(txtFechaValorInicio.SelectedDateString), CDate(txtFechaValorfin.SelectedDateString)) > 0 Then
                    MensajeError(Me, "La fecha de Inicio debe ser anterior o igual a la fecha de Termino")
                    Me.hdnErrorMsg.Value = "La Fecha de Inicio debe ser anterior o igua a la Fecha Final"
                    Exit Sub
                End If
                strFecIni = Format$(CDate(txtFechaValorInicio.Text), "yyyy-MM-dd")
                ''strFecIni = Format$(CDate(txtFechaValorInicio.SelectedDateString), "yyyy-MM-dd")
                strFecFin = Format$(CDate(txtFechaValorfin.Text), "yyyy-MM-dd")
                ''strFecFin = Format$(CDate(txtFechaValorfin.SelectedDateString), "yyyy-MM-dd")
            Else
                strFecIni = ""
                strFecFin = ""
            End If

            'Si no se selecciona la opcion de busqueda por Número de Contrato entonces:
            If Not rdbContrato.Checked Then
                If rdbCve.Checked Then intRdbCveCliente = 1
                If rdbRFC.Checked Then intRdbRFC = 1
                If rdbNom.Checked Then intrdbRazonSocial = 1

                If Len(Trim$(Me.txtCve.Text)) > 0 Then
                    intCveCliente = CInt(Trim$(txtCve.Text))
                End If

                strRFC = Trim$(txtRFC.Text)
                strRazonSocial = Trim$(txtNom.Text)
                strMensaje = ""
                strMensaje = ValidaCriteriosBusquedaPersona(intRdbCveCliente, intRdbRFC, intrdbRazonSocial, intCveCliente, strRFC, strRazonSocial)
                If Len(Trim$(strMensaje)) > 0 Then MensajeError(Me, strMensaje) : Exit Sub

                strMensaje = RevisaFirma(cmdBuscar, blnBit, intAcc, Me, strUser)
                If Len(Trim$(strMensaje)) > 0 Then
                    If Trim$(strMensaje) <> "ABRE MODAL" Then MensajeError(Me, strMensaje)
                    txtLogin.Text = ""
                    txtPwd.Text = ""
                    Me.hdnErrorMsg.Value = strMensaje
                    Exit Sub
                End If

                'Mensaje Permiso de Operacion
                If intAcc = 0 Then
                    MensajeError(Me, ObtenError(1))
                    Me.hdnErrorMsg.Value = ObtenError(1)
                    Exit Sub
                End If

                Try
                    objDs = objSN.ObtenDatasetPersona(intCveCliente, strRFC, strRazonSocial, intFgStatus, intOrden, strUser, 0, False, strMensaje, strFecOper, txtLogin.Text)
                Catch ex As Exception
                    AbreVentError(Me, 0, ex.Message)
                    Exit Sub
                End Try

                If Len(Trim(strMensaje)) > 0 Then
                    AbreVentError(Me, 1, strMensaje)
                    txtCve.Text = ""
                    txtRFC.Text = ""
                    txtNom.Text = ""
                    lblPais.Text = ""
                    Exit Sub
                End If
                If objDs Is Nothing OrElse objDs.Tables.Count = 0 OrElse objDs.Tables(0).Rows.Count = 0 Then
                    MensajeError(Me, "No se encontraron registros con el parámetro dado")
                    Me.hdnErrorMsg.Value = "El No. de Cliente es incorrecto o inexistente."
                    'Me.lbldMsg.Text = Me.hdnErrorMsg.Value
                    ''Me.msgConsultaCargos.Show("ProleaseNet", "No se encontraron registros con el parámetro dado", Nothing, New EO.Web.MsgBoxButton("OK", "on_button_clicked"))
                    'Me.dlgMsg.Show()
                    Me.txtEncontro.Text = ""
                    lblPais.Text = ""
                    Exit Sub
                End If
                'Si encuentra a más de una persona con los mismos criterios de búsqueda,
                'se abre una ventana con el resultado, para que el usuario seleccione a una persona.
                If Not objDs Is Nothing AndAlso objDs.Tables.Count > 0 AndAlso objDs.Tables(0).Rows.Count > 1 Then
                    sUrl.AppendFormat("window.open('")
                    sUrl.AppendFormat("./su_BuscaPersona.aspx?")
                    sUrl.AppendFormat("Nom={0}&Bandera=1&cveId={1}", Me.txtNom.Text, txtCve.ClientID)
                    sUrl.AppendFormat("&nomId={0}&rfcId={1}", txtNom.ClientID, txtRFC.ClientID)
                    sUrl.AppendFormat("&rdbCveId={0}", rdbCve.ClientID)
                    sUrl.AppendFormat("&strBoton={0}", cmdBuscar.ClientID)
                    sUrl.AppendFormat("', 'BusquedaPersona', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=900,height=400,left=100,top=100;');")
                    ScriptManager.RegisterStartupScript(Me, GetType(Button), "AbrePopup", sUrl.ToString, True)

                Else
                    txtNom.Text = objDs.Tables(0).Rows(0)("PNA_DS_NOMBRE")
                    txtRFC.Text = objDs.Tables(0).Rows(0)("PNA_CL_RFC")
                    txtCve.Text = objDs.Tables(0).Rows(0)("PNA_FL_PERSONA")
                    txtPJuridica.Text = objDs.Tables(0).Rows(0)("PNA_CL_PJURIDICA")

                    intCveCliente = objDs.Tables(0).Rows(0)("PNA_FL_PERSONA")
                    Dim objXmlp As System.Xml.XmlDocument = Nothing
                    Dim objSNp As New snLsenet.sn_clsPersona
                    objXmlp = objSNp.ObtenPersona(intCveCliente, strRFC, strRazonSocial, intFgStatus, intOrden, strUser, 0, False, strMensaje, strFecOper, strUsuFirma)
                    Dim intCvePais As String = objXmlp.ChildNodes(0).ChildNodes(0).SelectSingleNode("PAI_FL_CVE").InnerText.Trim
                    Dim objPais As Proleasenet.Clases.Pais
                    objPais = Proleasenet.Negocio.sn_clsPais.obtenerPais(intCvePais)
                    lblPais.Text = objPais.Pai_ds_nombre_espanol.Trim

                    'actualizamos el valor de la clave de cliente
                    intCveCliente = Val(Trim$(txtCve.Text))

                    ObtenerContratos(intCveCliente)
                    cmbContrato.Visible = True
                    txtContrato.Text = ""
                    txtContrato.Style.Add("display", "none")


                    Try 'Marredondo Tracker 9812 Modificaciones a pantallas para realizar filtros por empresa

[bFCruz]
                        objDs = objSNCP.ObtenMovimientosDS("", intCveCliente, cmbTmov.SelectedValue, cmbEsqFinan.SelectedValue, _
                                                            strFecIni, strFecFin, cmbMoneda.SelectedValue, cmbStatus.SelectedValue, strUser, intAcc, _
                                                            blnBit, strFecOper, "", strMensaje, 1, cmbEmpresa.SelectedValue)

                        'FCruz
                        Me.grdPba.SelectedItemIndex = -1
                        Me.grdPba.DataSource = objDs
                        Me.grdPba.DataBind()

[/bFCruz]

                        'If Not Request("PageNo") Is Nothing Then gvData.PageIndex = Request("PageNo")
                        decCapital_DG = 0
                        decInteres_DG = 0
                        decIVA_DG = 0
                        decTotal_DG = 0
                        decMontoPagado_DG = 0
                        decSaldo_DG = 0

                        arrCaracActFac = Nothing
                        ReDim arrCaracActFac(objDs.Tables(0).Rows.Count - 1)
                        For i As Integer = 0 To objDs.Tables(0).Rows.Count - 1
                            arrCaracActFac(i) = objDs.Tables(0).Rows(i).ItemArray(11).ToString.Trim
                        Next i
                        'gvDeuda.DataSource = objDs
                        'gvDeuda.DataBind()

                        'Marredondo TRACKER 9039
                        'GridView1.DataSource = objDs
                        'GridView1.DataBind()
                        'FIN TRACKER 9039
                    Catch ex As Exception
                        AbreVentError(Me, 1, ex.Message)
                        Exit Sub
                    End Try
                    If Len(Trim(strMensaje)) > 0 Then
                        AbreVentError(Me, 1, strMensaje)
                    End If
                    If objDs Is Nothing OrElse objDs.Tables.Count = 0 OrElse objDs.Tables(0).Rows.Count = 0 Then
                        MensajeError(Me, "No se localizó información de Movimientos")
                        Me.hdnErrorMsg.Value = "No se localizó información de Movimientos"
                        panTotal.Visible = False
                        Exit Sub
                    End If
                End If
            Else 'Busqueda por contrato
                If rdbContrato.Checked = True Then
                    cmbContrato.Items.Clear()
                    cmbContrato.Visible = False
                    txtContrato.Visible = True
                End If
                If cmbContrato.Items.Count = 0 Then
                    strContrato = txtContrato.Text.Trim
                Else
                    txtContrato.Text = cmbContrato.SelectedValue
                    strContrato = cmbContrato.SelectedValue
                End If

                Try
                    intCveCliente = objSN.ObtenClavePersona(strContrato)
                    If intCveCliente = 0 Then
                        MensajeError(Me, "El contrato especificado no existe")
                        Me.hdnErrorMsg.Value = "El contrato especificado no existe"
                        Exit Sub
                    End If
                    dsaux = aux.ObtenDatosContratoDS(strContrato, strMensaje)
                    If Not (Not dsaux Is Nothing AndAlso dsaux.Tables.Count > 0 AndAlso dsaux.Tables(0).Rows.Count > 0) Then
                        MensajeError(Me, "El contrato especificado no existe")
                        Me.hdnErrorMsg.Value = "El contrato especificado no existe"
                        Exit Sub
                    End If
                    cmbMoneda.SelectedValue = dsaux.Tables(0).Rows(0)("CTO_CL_MONEDA")
                    cmbEsqFinan.SelectedValue = ""

                    'ObtenerContratos(intCveCliente, txtContrato.Text.Trim)
                    'cmbContrato.Visible = True
                    'txtContrato.Text = ""
                    'txtContrato.Style.Add("display", "none")

                Catch ex As Exception
                    AbreVentError(Me, 0, ex.Message)
                    Exit Sub
                End Try

                If Len(Trim(strMensaje)) > 0 Then
                    AbreVentError(Me, 1, strMensaje)
                    txtCve.Text = ""
                    txtRFC.Text = ""
                    txtNom.Text = ""
                    lblPais.Text = ""
                    Exit Sub
                End If
                If intCveCliente = 0 Then
                    MensajeError(Me, "No se encontraron registros con el parámetro dado")
                    Me.hdnErrorMsg.Value = "No se encontraron registros con el parámetro dado"
                    lblPais.Text = ""
                    Exit Sub
                End If

                Try
                    objDs = objSN.ObtenDatasetPersona(intCveCliente, strRFC, strRazonSocial, intFgStatus, intOrden, strUser, 0, False, strMensaje, strFecOper, txtLogin.Text)
                Catch ex As Exception
                    AbreVentError(Me, 0, ex.Message)
                    Exit Sub
                End Try

                If Len(Trim(strMensaje)) > 0 Then
                    AbreVentError(Me, 1, strMensaje)
                    txtCve.Text = ""
                    txtRFC.Text = ""
                    txtNom.Text = ""
                    lblPais.Text = ""
                    Exit Sub
                End If
                If objDs Is Nothing OrElse objDs.Tables.Count = 0 OrElse objDs.Tables(0).Rows.Count = 0 Then
                    MensajeError(Me, "No se encontraron registros con el parámetro dado")
                    Me.hdnErrorMsg.Value = "No se encontraron registros con el parámetro dado"
                    Me.txtEncontro.Text = ""
                    lblPais.Text = ""
                    Exit Sub
                End If

                txtNom.Text = objDs.Tables(0).Rows(0)("PNA_DS_NOMBRE")
                txtRFC.Text = objDs.Tables(0).Rows(0)("PNA_CL_RFC")
                txtCve.Text = objDs.Tables(0).Rows(0)("PNA_FL_PERSONA")
                txtPJuridica.Text = objDs.Tables(0).Rows(0)("PNA_CL_PJURIDICA")

                intCveCliente = objDs.Tables(0).Rows(0)("PNA_FL_PERSONA")
                Dim objXmlp As System.Xml.XmlDocument = Nothing
                Dim objSNp As New snLsenet.sn_clsPersona
                objXmlp = objSNp.ObtenPersona(intCveCliente, strRFC, strRazonSocial, intFgStatus, intOrden, strUser, 0, False, strMensaje, strFecOper, strUsuFirma)
                Dim intCvePais As String = objXmlp.ChildNodes(0).ChildNodes(0).SelectSingleNode("PAI_FL_CVE").InnerText.Trim
                Dim objPais As Proleasenet.Clases.Pais
                objPais = Proleasenet.Negocio.sn_clsPais.obtenerPais(intCvePais)
                lblPais.Text = objPais.Pai_ds_nombre_espanol.Trim

                'actualizamos el valor de la clave de cliente
                intCveCliente = Val(Trim$(txtCve.Text))

                Try 'Marredondo Tracker 9812 Modificaciones a pantallas para realizar filtros por empresa
                    objDs = objSNCP.ObtenMovimientosDS(strContrato, 0, cmbTmov.SelectedValue, cmbEsqFinan.SelectedValue, _
                                                        strFecIni, strFecFin, cmbMoneda.SelectedValue, cmbStatus.SelectedValue, strUser, intAcc, _
                                                        blnBit, strFecOper, "", strMensaje, 1, cmbEmpresa.SelectedValue)

                    'If Not Request("PageNo") Is Nothing Then gvData.PageIndex = Request("PageNo")
                    decCapital_DG = 0
                    decInteres_DG = 0
                    decIVA_DG = 0
                    decTotal_DG = 0
                    decMontoPagado_DG = 0
                    decSaldo_DG = 0

                    arrCaracActFac = Nothing
                    ReDim arrCaracActFac(objDs.Tables(0).Rows.Count - 1)
                    For i As Integer = 0 To objDs.Tables(0).Rows.Count - 1
                        arrCaracActFac(i) = objDs.Tables(0).Rows(i).ItemArray(11).ToString.Trim
                    Next i

                    'FCruz
                    Me.grdPba.SelectedItemIndex = -1
                    Me.grdPba.DataSource = objDs
                    Me.grdPba.DataBind()

                    'gvDeuda.DataSource = objDs
                    'gvDeuda.DataBind()
                    'Marredondo TRACKER 9039
                    'GridView1.DataSource = objDs
                    'GridView1.DataBind()
                    'FIN TRACKER 9039

                Catch ex As Exception
                    AbreVentError(Me, 1, ex.Message)
                    Exit Sub
                End Try
                If Len(Trim(strMensaje)) > 0 Then
                    AbreVentError(Me, 1, strMensaje)
                End If
                If objDs Is Nothing OrElse objDs.Tables.Count = 0 OrElse objDs.Tables(0).Rows.Count = 0 Then
                    MensajeError(Me, "No se localizó información de Movimientos")
                    Me.hdnErrorMsg.Value = "No se localizó la informacion de Movimientos"
                    panTotal.Visible = False
                    Exit Sub
                End If
                cmbMoneda.Enabled = True
                cmbEsqFinan.Enabled = True
            End If

            Me.obten_Subtotales(objDs)

            hidMostraTabla.Value = "0"
            'gvDeuda.Style("display") = "inline"
            panTotal.Visible = True
        End Sub


Thanks in advance.
eo_support
Posted: Monday, July 5, 2010 12:12:29 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

The Grid always works with table because the grid data is always two dimensional. When you set the Grid's DataSource to a DataSet object, you should also set the Grid's DataTable property to the name of the table you wish the Grid to load. The Grid then loads that table.

If you wish to sort that table, you can get the table object, then change the Sort property for that table's DefaultView. For example:

Code: C#
ds.Tables["table_name"].DefaultView.Sort = "field_name DESC";


Note you must replace "table_name" and "field_name" with your real table name and field name. Also please keep in mind that this sorts all the data in memory. So if you have thousands of records then it probably won't work. In that case you should sort on the SQL level.

Thanks!
FCruz
Posted: Monday, July 5, 2010 3:00:11 PM
Rank: Member
Groups: Member

Joined: 6/4/2010
Posts: 16
Hi again,

Thanks for the tip, finally I resolve the issue in 3 steps.

1.- Create two variables to control the sortfield and sortorder.
Code: Visual Basic.NET
Dim sSortField As String = "[field to sort]"
        Dim sSortOrder As String = "[DESC or ASC]"


2.-In the event [grid]_ColumnSort I assign values and call my procedure to retrieve data and fill the dataset

Code: Visual Basic.NET
Protected Sub grdPba_ColumnSort(ByVal sender As Object, ByVal e As EO.Web.GridColumnEventArgs) Handles grdPba.ColumnSort
            'Que debe ir aquí ?
            Me.sSortField = e.Column.DataField
            Me.sSortOrder = IIf(e.Column.SortOrder = EO.Web.SortOrder.Ascending, "ASC", "DESC")
           
            obtenercargos()

        End Sub


Code: Visual Basic.NET
3.- Create a procedure where the dataset is ordered and fill the grid.
  Private Sub Fill_Grid(ByRef objDs As DataSet)
            If objDs.Tables.Count > 0 Then
                If objDs.Tables(objDs.Tables.Count - 1).Rows.Count > 0 Then
                    If Not Me.sSortField Is Nothing And Not Me.sSortOrder Is Nothing Then
                        objDs.Tables(0).DefaultView.Sort = Me.sSortField & " " & Me.sSortOrder
                    End If
                End If
            End If

            'FCruz
            Me.grd.SelectedItemIndex = -1
            Me.grd.DataSource = objDs
            Me.grd.DataBind()

        End Sub


Without their help I would have taken days to solve the problem.

Applause :d/
eo_support
Posted: Monday, July 5, 2010 3:17:47 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Great. Thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.