Solved

gridview paging is not working

Posted on 2014-01-03
7
214 Views
Last Modified: 2014-01-06
class file shown below:

Imports Microsoft.VisualBasic


Public Class TTReportsChangeofAddressExceptionGridView
    Inherits TTReportsGridViewFiller
    Implements IReportResult

    'Private _userId As Integer
    Private _userType As String
    Private _plpId As Integer

    Public Sub New(ByVal sDealers As String, ByVal sFinalizeDateFrom As String, ByVal sFinalizeDateTo As String, ByVal sExceptionSource As String)

        MyBase.New()

        _Dealers = WebFormHelper.ToSqlString(sDealers)

        Try : DateTime.TryParse(sFinalizeDateFrom, _FinalizedDateFrom)
        Catch ex As Exception : _FinalizedDateFrom = SqlTypes.SqlDateTime.Null : End Try

        Try : DateTime.TryParse(sFinalizeDateTo, _FinalizedDateTo)
        Catch ex As Exception : _FinalizedDateTo = SqlTypes.SqlDateTime.Null : End Try

        _ExceptionSource = WebFormHelper.ToSqlString(IIf(String.IsNullOrEmpty(sExceptionSource), "both", sExceptionSource.ToLower()))

        _UserID = UserSession.UserID
        _userType = Security.GetRuleValue("user_type")
        _plpId = UserSession.PrivateLabelPartnerID

    End Sub

    Public Overrides Sub DataBind(ByRef gv As GridView, ByVal iSortField As Integer, ByVal iSortDirection As Integer, ByRef dtOutput As DataTable, Optional ByVal bBindGrid As Boolean = True)

        Dim sStoredProc = "spTTReports_AddressException"

        Dim arrSqlParameters As SqlParameter() = { _
            New SqlParameter("@dealers", _Dealers), _
            New SqlParameter("@finaldatefrom", _FinalizedDateFrom), _
            New SqlParameter("@finaldateto", _FinalizedDateTo), _
            New SqlParameter("@exceptionSource", _ExceptionSource), _
            New SqlParameter("@plpId", _plpId), _
            New SqlParameter("@userId", _UserID), _
            New SqlParameter("@userType", _userType) _
            }

        Dim arrDSColumnNames() As String = {"t21 ID", "Deal #", "Dealer Name", "Customer Name", _
                                             "Old Address", "New Address", _
                                            "Deal Date", "Days Since Deal", _
                                            "Finalized Date", "Days Since Finalized", _
                                            "Source", "Transmitted Date"}

        MyBase.DataBind(gv, iSortField, iSortDirection, sStoredProc, arrSqlParameters, arrDSColumnNames)
        dtOutput = _dt

        If bBindGrid Then
            AddHandler gv.RowDataBound, AddressOf gv_RowDataBound

            MyBase.FillGridView(gv)
        End If

    End Sub

    Private Sub gv_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.Header Then
            For i As Integer = 0 To e.Row.Cells.Count - 1
                Dim txt As String = CType(e.Row.Cells(i).Controls(0), LinkButton).Text
                Dim href As New HtmlAnchor
                href.InnerText = txt
                href.HRef = "javascript:sortGrid(" + (i + 1).ToString() + ");"

                e.Row.Cells(i).Controls.Clear()
                e.Row.Cells(i).Controls.Add(href)
            Next
        End If

        ' cause a string like "blah;blah;blah" to appear in a column
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Cells(3).Text = e.Row.Cells(3).Text.Replace(";", ";<br>")
        End If

    End Sub

    Public Sub PrepareGrid(ByVal gv As System.Web.UI.WebControls.GridView) Implements IReportResult.PrepareGrid
        gv.AllowPaging = True
        gv.AllowSorting = True
    End Sub

    Public Sub PrepareGridViewColumns(ByRef gv As System.Web.UI.WebControls.GridView, ByVal SelectedDate As String) Implements IReportResult.PrepareGridViewColumns
        Dim col1, col2, col3, col4, col5, col6, col7, col8, col9, col10, col11, col12 As New BoundField
        col1.HeaderText = "t21 ID"
        col1.DataField = "t21 ID"
        col1.SortExpression = "1"

        col2.HeaderText = "Deal #"
        col2.DataField = "Deal #"
        col2.SortExpression = "2"

        col3.HeaderText = "Dealer Name"
        col3.DataField = "Dealer Name"
        col3.SortExpression = "3"

        col4.HeaderText = "Customer Name"
        col4.DataField = "Customer Name"
        col4.SortExpression = "4"

        col5.HeaderText = "Old Address"
        col5.DataField = "Old Address"
        col5.SortExpression = "5"

        col6.HeaderText = "New Address"
        col6.DataField = "New Address"
        col6.SortExpression = "6"

        col7.HeaderText = "Deal Date"
        col7.DataField = "Deal Date"
        col7.SortExpression = "7"

        col8.HeaderText = "Days Since Deal"
        col8.DataField = "Days Since Deal"
        col8.SortExpression = "8"
        col8.ItemStyle.HorizontalAlign = HorizontalAlign.Center

        col9.HeaderText = "Finalized Date"
        col9.DataField = "Finalized Date"
        col9.SortExpression = "9"

        col10.HeaderText = "Days Since Final"
        col10.DataField = "Days Since Finalized"
        col10.SortExpression = "10"
        col10.ItemStyle.HorizontalAlign = HorizontalAlign.Center

        col11.HeaderText = "Source"
        col11.DataField = "Source"
        col11.SortExpression = "11"

        col12.HeaderText = "Transmitted Date"
        col12.DataField = "Transmitted Date"
        col12.SortExpression = "12"

        gv.Columns.Add(col1)
        gv.Columns.Add(col2)
        gv.Columns.Add(col3)
        gv.Columns.Add(col4)
        gv.Columns.Add(col5)
        gv.Columns.Add(col6)
        gv.Columns.Add(col7)
        gv.Columns.Add(col8)
        gv.Columns.Add(col9)
        gv.Columns.Add(col10)
        gv.Columns.Add(col11)
        gv.Columns.Add(col12)
    End Sub

    Public Function PrepareModifiedColumnName(ByVal ColumnName As String) As String Implements IReportResult.PrepareModifiedColumnName
        Return ColumnName
    End Function

    Public Sub PrepareReportHTML(ByVal tbl As System.Web.UI.WebControls.Table, ByVal dt As System.Data.DataTable) Implements IReportResult.PrepareReportHTML
        Dim bDisplayColumnTotals As Boolean = False

        Dim tr As New TableRow
        Dim td(dt.Columns.Count - 1) As TableCell
        Dim arrTotal(dt.Columns.Count - 1) As Double
        Dim bSubTotal As Boolean = True

        For i As Integer = LBound(td) To UBound(td)
            td(i) = New TableCell()
            td(i).Text = PrepareModifiedColumnName(dt.Columns(i).ColumnName)
            td(i).Font.Names = New String() {"Arial"}
            td(i).Font.Size = FontUnit.Point(8)
            td(i).Font.Bold = True
            td(i).Wrap = True

            td(i).Style("border-bottom") = "2px solid black"
            tr.Cells.Add(td(i))

            ' Reset Column Totals
            If bDisplayColumnTotals Then arrTotal(i) = 0
        Next
        tbl.Rows.Add(tr)

        For r As Integer = 0 To dt.Rows.Count - 1
            tr = New TableRow
            For i As Integer = LBound(td) To UBound(td)
                td(i) = New TableCell()
                td(i).Font.Names = New String() {"Arial"}
                td(i).Font.Size = FontUnit.Point(8)
                If IsDBNull(dt.Rows(r)(i)) Then
                    td(i).Text = ""
                Else
                    td(i).Text = dt.Rows(r)(i)
                End If

                If r Mod 2 = 0 Then
                    td(i).BackColor = Drawing.Color.FromArgb(255, 255, 255)
                Else
                    td(i).BackColor = Drawing.Color.FromArgb(225, 225, 225)
                End If

                '' Check if this is a SubTotal Row
                'bSubTotal = False
                'If bSubTotal Then
                '    td(i).BackColor = Drawing.Color.FromArgb(201, 202, 203)
                'End If

                '' Add to Total
                'If bDisplayColumnTotals Then
                '    If IsNumeric(dt.Rows(r)(i)) Then
                '        arrTotal(i) = arrTotal(i) + dt.Rows(r)(i)
                '    End If
                'End If

                If (i = 6 OrElse i = 8) Then
                    td(i).HorizontalAlign = HorizontalAlign.Center
                End If

                tr.Cells.Add(td(i))
            Next
            tbl.Rows.Add(tr)
        Next

        ' Optionally display Footer
        If bDisplayColumnTotals Then
            tr = New TableRow

            For i As Integer = LBound(td) To UBound(td)
                td(i) = New TableCell()

                td(i).Text = arrTotal(i)

                td(i).Font.Names = New String() {"Arial"}
                td(i).Font.Size = FontUnit.Point(8)
                td(i).Font.Bold = True
                td(i).Wrap = True
                td(i).Style("border-top") = "2px solid black"
                tr.Cells.Add(td(i))
            Next
            tbl.Rows.Add(tr)
        End If

    End Sub

    Public Sub PrepareReportSpecificGridView(ByVal divCanvas As System.Web.UI.HtmlControls.HtmlGenericControl, ByVal lbl As System.Web.UI.WebControls.Label, ByVal ddlPageSize As System.Web.UI.WebControls.DropDownList) Implements IReportResult.PrepareReportSpecificGridView
        divCanvas.Style.Add("width", "1550px")
    End Sub

    Public Sub PrepareReportSpecificVariables(ByRef dt As System.Data.DataTable, _
                                              ByRef xslFile As String, _
                                              ByRef ReportTitle As String, _
                                              ByVal bTotalColumns As Boolean) Implements IReportResult.PrepareReportSpecificVariables
        'xslFile = "ScanningExceptions.xsl"
        ReportTitle = "Change of Address Exceptions"
    End Sub

End Class

Open in new window

0
Comment
Question by:Meinhoonaa
  • 3
  • 2
  • 2
7 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39754345
Any error messages or is it doing nothing?
0
 

Author Comment

by:Meinhoonaa
ID: 39754351
No error messages, it is doing nothing.
0
 
LVL 10

Expert Comment

by:Monica P
ID: 39755997
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 18

Expert Comment

by:Jerry Miller
ID: 39758341
Do you have a pageIndexChanging Event? If so does your code ever hit it? I have found that when you dynamically create gridviews you need to manually handle the paging and sorting events as well.

See Akila P's link for a couple of examples.
0
 

Author Comment

by:Meinhoonaa
ID: 39758434
can u send me the links?
0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 39758635
For Example :

In aspx :

<asp:GridView ID="GridVwPagingSorting" runat="server" AutoGenerateColumns="False"
                Font-Names="Verdana" AllowPaging="True" AllowSorting="True" PageSize="5" Width="75%"
               OnPageIndexChanging="PageIndexChanging" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" OnSorting="Sorting">

In Code :

protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridVwPagingSorting.PageIndex = e.NewPageIndex;
            DataView dvEmployee = Getdata();
            GridVwPagingSorting.DataSource = dvEmployee;
            GridVwPagingSorting.DataBind();
        }
0
 

Author Closing Comment

by:Meinhoonaa
ID: 39759850
tks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now