Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:37:55+00:00 2026-05-27T00:37:55+00:00

My Gridview won’t page or sort. By this I mean that the data in

  • 0

My Gridview won’t page or sort. By this I mean that the data in the GridView doesn’t change when I try to sort by a column or when I try to page through the GridView.

I have it inside an UpdatePanel on a user control (.ascx). The code below works fine when I try it outside of the user control.

Here’s my code:

    <asp:GridView runat="server" ID="grdStats" AutoGenerateColumns="false" Width="100%" AllowSorting="true"
        AllowPaging="true" PageSize="20" PagerSettings-Mode="NumericFirstLast" PagerSettings-Position="TopAndBottom">
        <Columns>
            <asp:BoundField DataField="campaignname" HeaderText="Campaign Name" SortExpression="campaignname" />
            <asp:BoundField DataField="site_name" HeaderText="Outlet" SortExpression="site_name" />
            <asp:BoundField DataField="filename" HeaderText="Media" SortExpression="filename" />
            <asp:BoundField DataField="playinterval" HeaderText="Play Interval" SortExpression="playinterval" />
        </Columns>
    </asp:GridView>

Here’s the backend:

Protected Sub grdStats_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdStats.PageIndexChanging
    grdStats.PageIndex = e.NewPageIndex
    GetCampaignData()
End Sub

Protected Sub grdStats_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles grdStats.Sorting

    If e.SortExpression = ViewState("sortExpr") Then
        ViewState("sortExpr") = e.SortExpression & " desc"
    Else
        ViewState("sortExpr") = e.SortExpression
    End If

    GetCampaignData()

End Sub

' ######## POPULATE DATA #########

Private Sub GetCampaignData(Optional ByVal CompanyID As Integer = 0)
    Dim sql As String = Nothing

    ' Check user access level.
    If Session("userlevel") = 1 Then
        ' Current user is admin.

        ' If a company has been filtered, get it's data, else, get all campaign data.
        If CompanyID <> 0 Then
            sql = "SELECT" & vbCrLf & _
            "   a.campaignid," & vbCrLf & _
            "   a.companyid," & vbCrLf & _
            "   a.campaignname," & vbCrLf & _
            "   a.filename," & vbCrLf & _
            "   startdate," & vbCrLf & _
            "   enddate," & vbCrLf & _
            "   a.playinterval," & vbCrLf & _
            "   a.ActiveStatus," & vbCrLf & _
            "   b.*," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS c" & vbCrLf & _
            "       WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
            "       AND c.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS today," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS d" & vbCrLf & _
            "       WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
            "       AND d.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS past_week," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS e" & vbCrLf & _
            "       WHERE e.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS playcount" & vbCrLf & _
            "FROM campaigns AS a" & vbCrLf & _
            "INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
            "WHERE a.ActiveStatus = 1" & vbCrLf & _
            "AND a.companyid = " & CompanyID

        Else
            sql = "SELECT" & vbCrLf & _
            "   a.campaignid," & vbCrLf & _
            "   a.companyid," & vbCrLf & _
            "   a.campaignname," & vbCrLf & _
            "   a.filename," & vbCrLf & _
            "   startdate," & vbCrLf & _
            "   enddate," & vbCrLf & _
            "   a.playinterval," & vbCrLf & _
            "   a.ActiveStatus," & vbCrLf & _
            "   b.*," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS c" & vbCrLf & _
            "       WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
            "       AND c.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS today," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS d" & vbCrLf & _
            "       WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
            "       AND d.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS past_week," & vbCrLf & _
            "   (SELECT COUNT(*)" & vbCrLf & _
            "       FROM campaignstats AS e" & vbCrLf & _
            "       WHERE e.campaignid = a.campaignid" & vbCrLf & _
            "   ) AS playcount" & vbCrLf & _
            "FROM campaigns AS a" & vbCrLf & _
            "INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
            "WHERE a.ActiveStatus = 1"


        End If
    Else
        ' User is not an admin. 
        sql = "SELECT" & vbCrLf & _
        "   a.campaignid," & vbCrLf & _
        "   a.companyid," & vbCrLf & _
        "   a.campaignname," & vbCrLf & _
        "   a.filename," & vbCrLf & _
        "   startdate," & vbCrLf & _
        "   enddate," & vbCrLf & _
        "   a.playinterval," & vbCrLf & _
        "   a.ActiveStatus," & vbCrLf & _
        "   b.*," & vbCrLf & _
        "   (SELECT COUNT(*)" & vbCrLf & _
        "       FROM campaignstats AS c" & vbCrLf & _
        "       WHERE DAY(date_played) = DAY(CURRENT_DATE)" & vbCrLf & _
        "       AND c.campaignid = a.campaignid" & vbCrLf & _
        "   ) AS today," & vbCrLf & _
        "   (SELECT COUNT(*)" & vbCrLf & _
        "       FROM campaignstats AS d" & vbCrLf & _
        "       WHERE date_played > CURRENT_DATE - INTERVAL 7 DAY" & vbCrLf & _
        "       AND d.campaignid = a.campaignid" & vbCrLf & _
        "   ) AS past_week," & vbCrLf & _
        "   (SELECT COUNT(*)" & vbCrLf & _
        "       FROM campaignstats AS e" & vbCrLf & _
        "       WHERE e.campaignid = a.campaignid" & vbCrLf & _
        "   ) AS playcount" & vbCrLf & _
        "FROM campaigns AS a" & vbCrLf & _
        "INNER JOIN companies AS b ON a.companyid = b.companyid" & vbCrLf & _
        "WHERE a.ActiveStatus = 1" & vbCrLf & _
        "AND a.companyid = " & CInt(Session("companyid"))
    End If

    grdCampaigns.DataSource = get_data(sql)
    grdCampaigns.DataBind()

    For i As Integer = 0 To grdCampaigns.Rows.Count - 1
        grdCampaigns.Rows(i).Cells(2).Text = Microsoft.VisualBasic.Left(grdCampaigns.Rows(i).Cells(2).Text, 10)
        grdCampaigns.Rows(i).Cells(3).Text = Microsoft.VisualBasic.Left(grdCampaigns.Rows(i).Cells(3).Text, 10)
    Next
End Sub

Public Function get_data(ByVal SQLStatement As String) As DataView

    'Populates the datatable
    Dim dt As Data.DataTable

    dt = db.GetDataTable(SQLStatement)

    Dim dv As System.Data.DataView = New System.Data.DataView(dt)

    If Not ViewState("sortExpr") Is Nothing Then
        dv.Sort = ViewState("sortExpr")
    Else
        dv = dt.DefaultView
    End If

    Session("dv5") = dv
    Return dv
End Function

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:37:55+00:00Added an answer on May 27, 2026 at 12:37 am

    My apologies the code I pasted in the question, although correct for it’s purpose, was not the right code relevant to this question. That said, I’d like to thank you Icarus for taking the time to look over my code.

    The paging/sorting works. What I did to fix it was to replace the call to GetCampaignData() within the PageIndexChanging and Sorting event handlers to the SQL code and data binding methods required to give me the results I needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET GridView that just won't sort! I'm sure that I am
I have a GridView that allows editing the values in every column, in every
I have a GridView that is customized by each page that uses it. The
I have a simple gridview ItemTemplate that looks like this: <asp:TemplateField HeaderText=User> <ItemTemplate> <a
I have a custom GridView that will show 6 rows of data as a
In gridview's column i have a linkbutton and a label under it. I want
I have a GridView control in an Asp.net application, that has a <asp:buttonField> of
I have a GridView where one column is bound to an object property containing
I have a GridView defined like this: <asp:GridView ID=myGridView ruant=server> <asp:BoundField DataField=myField /> <asp:CommandField
I have a GridView that I would like to bind to an ObjectDataSource. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.