HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

Rate It (26)

Last post 07-30-2007 2:56 AM by krishanmanral. 185 replies.

Sort Posts:

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    06-28-2007, 9:37 AM
    Locked
    • Member
      2 point Member
    • mliolios
    • Member since 06-28-2007, 1:29 PM
    • Posts 1

    Paula,  Is it possible to explaine what did you do, or better to post once again the final working code?

    Thanks in advande

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    06-28-2007, 2:38 PM
    Locked
    • Member
      45 point Member
    • jeeva.net
    • Member since 06-11-2007, 7:50 AM
    • Posts 16

    Hi Ryan,

    That was a nice article. i tried converting the same to VB.net.. i'm hitting on an error in the following piece of code

    Protected Sub SearchGrid_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SearchGrid.Sorting
            Dim datatab As DataTable = SearchGrid.DataSource
            Dim datavw As New DataView(datatab)
            datavw.Sort = e.SortExpression.ToString + " " + ConvertSortDirectionToSql(e.SortDirection)           'this is where i get the error
            SearchGrid.DataSource = datavw
            SearchGrid.DataBind()

        End Sub

     When i click on the first column to sort,   it throws this message "Conversion from string "StudentID " to type 'Double' is not valid"
    Can you please help me ? Please see i'm using VB.net
     
    My complete code is as follows
     
    Private Function ConvertSortDirectionToSql(ByVal sortdirect As String) As SortDirection
            Dim newsortdirection As String
            Select Case (sortdirect)
                Case SortDirection.Ascending
                    newsortdirection = "asc"
                Case SortDirection.Descending
                    newsortdirection = "desc"
                Case Else
                    newsortdirection = "asc"
            End Select
            Return (newsortdirection)
        End Function
    
     Protected Sub SearchGrid_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SearchGrid.Sorting
            Dim datatab As DataTable = SearchGrid.DataSource
            Dim datavw As New DataView(datatab)
            datavw.Sort = e.SortExpression.ToString + " " + ConvertSortDirectionToSql(e.SortDirection)
            SearchGrid.DataSource = datavw
            SearchGrid.DataBind()
    
        End Sub
     
    Regards,
    Jeeva

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-04-2007, 9:15 AM
    Locked
    • Member
      8 point Member
    • rahilameen
    • Member since 07-04-2007, 1:12 PM
    • Posts 12

     

    hi,

    i am a new member of this goup and new to asp.net too.

    i tried the above code to sort the grid manually.but its showing following error

    what to do?

    please help me

    i had stucked at this level of my program.

    regards,

    thanks in advance,

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-04-2007, 9:17 AM
    Locked
    • Member
      8 point Member
    • rahilameen
    • Member since 07-04-2007, 1:12 PM
    • Posts 12

    hi,

    i am a new member of this goup and new to asp.net too.

    i tried the above code to sort the grid manually.but its showing following error

    "The name 'sortDirection' does not exist in the current context"

    what to do?

    please help me

    i had stucked at this level of my program.

    regards,

    thanks in advance,

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-04-2007, 9:45 AM
    Locked
    • Member
      6 point Member
    • Raafat4
    • Member since 05-26-2007, 9:42 AM
    • Posts 3

    Hi ,

    Write this function:

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)

    {

    string newSortDirection = String.Empty;switch (sortDireciton)

    {

    case SortDirection.Ascending:

    newSortDirection = "ASC";

    break;

    case SortDirection.Descending:

    newSortDirection = "DESC";

    break;

    }

    return newSortDirection;

    }

    There is an event in the GridView events called Sorting ,put the code velow in it:

    protected void gvDataSources_Sorting(object sender, GridViewSortEventArgs e)

    {

    DataTable dt = new DataTable();

    dt = LoadDataSources().Tables[0]; // LoadDataSources() function that return DataSet and the GridView Get its data from it

    if (dt != null)

    {

    DataView dvSort = new DataView(dt);

    dvSort.Sort = e.SortExpression;

    dvSort.Sort = e.SortExpression +
    " " + ConvertSortDirectionToSql(e.SortDirection);

    gvDataSources.DataSource = dvSort;

    gvDataSources.DataBind();

    }

    }

     

    Regards,

    Ra'fat

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-04-2007, 6:53 PM
    Locked

    This is very helpful but can someone translate this code in to VB.NET for those of us noobies out there:

     

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)

    {

    string newSortDirection = String.Empty;

    switch (sortDirection)

    {

    case SortDirection.Ascending:newSortDirection = "ASC";

    break;

    case SortDirection.Descending:

    newSortDirection = "DESC";

    break;

    }

    return newSortDirection

    }

    protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

    gridView.PageIndex = e.NewPageIndex;

    gridView.DataBind();

    }

    protected void gridView_Sorting(object sender, GridViewSortEventArgs e)

    {

    DataTable dataTable = gridView.DataSource
    as DataTable;if (dataTable != null)

    {

    DataView dataView = new DataView(dataTable);

    dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

    gridView.DataSource = dataView;

    gridView.DataBind();

    }

    }

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-04-2007, 7:25 PM
    Locked

    Ryan - this is very helpful but can you post this code in VB.NET?

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-05-2007, 5:22 AM
    Locked
    • Member
      6 point Member
    • Raafat4
    • Member since 05-26-2007, 9:42 AM
    • Posts 3

    Hi,

    I am Ra'fat not Ryan ,

    But i forget  the VB.NET Syntax, specially Function Definition

    Try this code:

    private string ConvertSortDirectionToSql(SortDirection sortDireciton)

    {

    Dim newSortDirection as String

    newSortDirection = " "

    switch (sortDireciton)

    {

    case SortDirection.Ascending:

    newSortDirection = "ASC"

    break

    case SortDirection.Descending:

    newSortDirection = "DESC"break

    }

    return newSortDirection

    }

    There is an event in the GridView events called Sorting ,put the code velow in it:

    protected void gvDataSources_Sorting(object sender, GridViewSortEventArgs e)

    {

    Dim dt as new DataTable

    dt = LoadDataSources().Tables(0); ' LoadDataSources() function that return DataSet and the GridView Get its data from it

    if (dt <> null) Dim dvSortas new DataView(dt)

    dvSort.Sort = e.SortExpression

    dvSort.Sort = e.SortExpression &
    " " & ConvertSortDirectionToSql(e.SortDirection)

    gvDataSources.DataSource = dvSort

    gvDataSources.DataBind()

    End If

    }

     

    Best Regards

    Ra'fat

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-05-2007, 10:21 AM
    Locked
    • All-Star
      30,698 point All-Star
    • StrongTypes
    • Member since 12-13-2005, 4:21 PM
    • California
    • Posts 6,007
    • ASPInsiders
      Moderator
      TrustedFriends-MVPs

    mcmillan_associates@hotmail.com:
    Ryan - this is very helpful but can you post this code in VB.NET?

    There is a VB.NET version.

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-05-2007, 10:52 AM
    Locked

    like you i am a new member,also to asp.net.

    my question is can you not accomplish this via asp.net?

    i am not sure what you are trying to achieve.but in time i suppose i will come across its use.so i have decided to save a copy of code...just in case.

    i would like to create own websites,like you.

    are there any useful sites where you can get useful code/examples from

    Filed under:
  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-10-2007, 5:18 PM
    Locked
    • Member
      156 point Member
    • pelegk2
    • Member since 12-17-2004, 7:08 AM
    • Israel
    • Posts 58
    when i am using the

    productsGridView_PageIndexChanging

    i see in the debbuger that the function is called twice

    why is that?

     

    thnaks i nadvance

    peleg

    Israel the best place to live in - after heaven (but no one wants to go there so fast!)
  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-10-2007, 6:35 PM
    Locked
    • Member
      6 point Member
    • Mr Blue Coat
    • Member since 05-09-2007, 7:57 PM
    • Posts 4

     Excellent post - Thanks!

    Here's my newbie ASP.NET variation for SQL Server using Session variables (instead of ViewState) and support for paging, sorting, data filtering and selecting:

     web.config:

    <connectionStrings>
        <add name="MyConnectionString" connectionString="Data Source=<SERVER>;Initial Catalog=<DATABASE>;Persist Security Info=True;User ID=<USER>;Password=<PASSWORD>" providerName="System.Data.SqlClient"/>
      </connectionStrings>

    app_code (DatabaseConnection.vb):

    Imports Microsoft.VisualBasic
    Imports System.Data
    Imports System.Data.SqlClient

    Public Class DatabaseConnection

        Public Shared connection As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString)

    End Class

    app_code (Utils.vb):

    Imports Microsoft.VisualBasic
    Imports System.Web.HttpContext
    Imports System.Data
    Imports System.Data.SqlClient
    Imports DatabaseConnection

    Public Class Utils

    Public Shared Function GetCompareStatement(ByVal firstValue As String, ByVal secondValue As String, ByVal operation As String) As String
            Select Case operation
                Case "Contains"
                    Return "LIKE '%" + firstValue + "%' "
                Case "Begins with"
                    Return "LIKE '" + firstValue + "%' "
                Case "Ends with"
                    Return "LIKE '%" + firstValue + "' "
                Case "Equals"
                    Return "= '" + firstValue + "' "
                Case "Date Equals"
                    Return "= CONVERT(DATETIME, '" + firstValue + "', 101) "
                Case "After"
                    Return "> CONVERT(DATETIME, '" + firstValue + "', 101) "
                Case "Before"
                    Return "< CONVERT(DATETIME, '" + firstValue + "', 101) "
                Case "Between"
                    Return "BETWEEN CONVERT(DATETIME, '" + firstValue + "', 101) AND CONVERT(DATETIME, '" + secondValue + "', 101) "
                Case Else
                    Return ""
            End Select
        End Function

        Public Shared Sub BindPagingSortingGridView(ByVal query As String, ByVal gridViewControl As GridView)
            'Binds Paging/Sorting GridView with data from the specified query
            Dim sqlComm As SqlCommand
            Dim sqlReader As SqlDataReader
            Dim dataTableControl As New DataTable()
            Dim dataTableRowCount As Integer

            sqlComm = New SqlCommand(query, connection)
            sqlReader = sqlComm.ExecuteReader()
            dataTableControl.Load(sqlReader)
            dataTableRowCount = dataTableControl.Rows.Count

            If dataTableRowCount > 0 Then
                gridViewControl.DataSource = dataTableControl
                gridViewControl.DataBind()
            End If

            sqlReader.Close()
        End Sub

        Public Shared Function SortDataTable(ByVal dataTable As DataTable, ByVal isPageIndexChanging As Boolean) As DataView
            If Not dataTable Is Nothing Then
                Dim dataView As New DataView(dataTable)
                If GridViewSortExpression <> String.Empty Then
                    If isPageIndexChanging Then
                        dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)
                    Else
                        dataView.Sort = String.Format("{0} {1}", GridViewSortExpression, GetSortDirection())
                    End If
                End If
                Return dataView
            Else
                Return New DataView()
            End If
        End Function

        Public Shared Property GridViewSortBLOCKED EXPRESSION As String
            Get
                Return IIf(Current.Session("SortBLOCKED EXPRESSION = Nothing, String.Empty, Current.Session("SortBLOCKED EXPRESSION)
            End Get
            Set(ByVal value As String)
                Current.Session("SortBLOCKED EXPRESSION = value
            End Set
        End Property

        Private Shared Function GetSortDirection() As String
            Select Case GridViewSortDirection
                Case "ASC"
                    GridViewSortDirection = "DESC"
                Case "DESC"
                    GridViewSortDirection = "ASC"
            End Select
            Return GridViewSortDirection
        End Function

        Public Shared Property GridViewSortDirection() As String
            Get
                Return IIf(Current.Session("SortDirection") = Nothing, "ASC", Current.Session("SortDirection"))
            End Get
            Set(ByVal value As String)
                Current.Session("SortDirection") = value
            End Set
        End Property

    End Class

    aspx page:

                    <asp:GridView ID="SupplierGridView" CssClass="datatable" Width="100%" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                            EmptyDataText="No records found" PageSize="15" runat="server">
                        <Columns>
                            <asp:ButtonField ButtonType="Link" Text="Select" CommandName="SELECT" />
                            <asp:BoundField DataField="ENT_SUPPLIER_NBR" HeaderText="ESD Number" SortExpression="ENT_SUPPLIER_NBR" />
                            <asp:BoundField DataField="SUP_NAME1" HeaderText="Name" SortExpression="SUP_NAME1" />
                            <asp:BoundField DataField="STREET" HeaderText="Street" SortExpression="STREET" />
                            <asp:BoundField DataField="CITY" HeaderText="City" SortExpression="CITY" />
                            <asp:BoundField DataField="STATE_REGION" HeaderText="State" SortExpression="STATE_REGION" />
                            <asp:BoundField DataField="ACTIVE" HeaderText="ACTIVE" SortExpression="ACTIVE" />
                        </Columns>
                    </asp:GridView>

     vb page:

    Imports System.Data
    Imports System.Data.SqlClient
    Imports Utils
    Imports DatabaseConnection

    ...

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
           If Not Page.IsPostBack Then
                ' Clear user paging/sort
                Session("CurrentPage") = 0
                Session("SortBLOCKED EXPRESSION = Nothing
                GridViewSortDirection = "ASC"
                ' Set current query
                Session("CurrentQuery") = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_SUPPLIERS WHERE ENT_SUPPLIER_NBR IS NOT NULL AND ACTIVE = 'Active' ORDER BY SUP_NAME1 ASC"
            End If

            ' Bind GridView to current query
            connection.Open()
            BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
            connection.Close()

    End Sub

     Protected Sub ApplyFilterButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ApplyFilterButton.Click
            ' Filter GridView contents

            Dim tempQuery As String = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_Suppliers WHERE ENT_SUPPLIER_NBR IS NOT NULL"
            ' Filter ESD Number
            If Len(EsdNumberTextBox.Text) > 0 Then
                tempQuery += " AND ENT_SUPPLIER_NBR " & GetCompareStatement(EsdNumberTextBox.Text, Nothing, EsdNumberDropDownList.SelectedValue)
            End If
            ' Filter Supplier Name
            If Len(SupplierNameTextBox.Text) > 0 Then
                tempQuery += " AND SUP_NAME1 " & GetCompareStatement(SupplierNameTextBox.Text, Nothing, SupplierNameDropDownList.SelectedValue)
            End If
            ' Filter Supplier City
            If Len(SupplierCityTextBox.Text) > 0 Then
                tempQuery += " AND CITY " & GetCompareStatement(SupplierCityTextBox.Text, Nothing, SupplierCityDropDownList.SelectedValue)
            End If
            ' Filter Supplier State
            If Len(SupplierStateTextBox.Text) > 0 Then
                tempQuery += " AND STATE_REGION " & GetCompareStatement(SupplierStateTextBox.Text, Nothing, SupplierStateDropDownList.SelectedValue)
            End If
            ' Filter Active
            If ActiveDropDownList.SelectedIndex > 0 Then
                tempQuery += " AND Active = '" & ActiveDropDownList.SelectedValue & "'"
            End If

            ' Clear user paging/sort
            Session("CurrentPage") = 0
            Session("SortBLOCKED EXPRESSION = Nothing
            GridViewSortDirection = "ASC"

            ' Update current query
            Session("CurrentQuery") = Trim(tempQuery) & " ORDER BY SUP_NAME1 ASC"

            ' Bind GridView to current query
            connection.Open()
            BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
            connection.Close()

        End Sub

       Protected Sub ShowAllButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ShowAllButton.Click
            ' Show all suppliers

            ' Clear filter options
            EsdNumberDropDownList.SelectedIndex = 0
            SupplierNameDropDownList.SelectedIndex = 0
            SupplierCityDropDownList.SelectedIndex = 0
            SupplierStateDropDownList.SelectedIndex = 0
            ActiveDropDownList.SelectedIndex = 0
            EsdNumberTextBox.Text = ""
            SupplierNameTextBox.Text = ""
            SupplierCityTextBox.Text = ""
            SupplierStateTextBox.Text = ""

            ' Clear user paging/sort
            Session("CurrentPage") = 0
            Session("SortDirection") = Nothing

            ' Update current query
            Session("CurrentQuery") = "SELECT ENT_SUPPLIER_NBR, SUP_NAME1, STREET, CITY, STATE_REGION, Active FROM INFO_Suppliers WHERE ENT_SUPPLIER_NBR IS NOT NULL ORDER BY SUP_NAME1 ASC"

            ' Bind GridView to current query
            connection.Open()
            BindPagingSortingGridView(Session("CurrentQuery"), SupplierGridView)
            connection.Close()
        End Sub

       Protected Sub SupplierGridView_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SupplierGridView.SelectedIndexChanged
            ' Bind current data
            SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, True)
            SupplierGridView.PageIndex = Session("CurrentPage")
            SupplierGridView.DataBind()

            ' <This is the row the user selected -- do with it what you want>
            supplierNumber.Text = SupplierGridView.SelectedRow.Cells(1).Text
            supplierName.Text = SupplierGridView.SelectedRow.Cells(2).Text
            supplierStreet.Text = SupplierGridView.SelectedRow.Cells(3).Text
          ...


            ' Clear session variables
            Session("CurrentPage") = Nothing
            Session("SortBLOCKED EXPRESSION = Nothing
            Session("CurrentQuery") = Nothing

        End Sub

        Protected Sub SupplierGridView_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles SupplierGridView.Sorting
            GridViewSortExpression = e.SortExpression
            Dim pageIndex As Integer = SupplierGridView.PageIndex
            If SupplierGridView.DataSource.GetType().ToString = "System.Data.DataTable" Then
                SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, False)
                SupplierGridView.PageIndex = Session("CurrentPage")
                SupplierGridView.DataBind()
            End If
        End Sub

        Protected Sub SupplierGridView_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles SupplierGridView.PageIndexChanging
            If SupplierGridView.DataSource.GetType().ToString = "System.Data.DataTable" Then
                SupplierGridView.DataSource = SortDataTable(SupplierGridView.DataSource, True)
                SupplierGridView.PageIndex = e.NewPageIndex
                Session("CurrentPage") = e.NewPageIndex
                SupplierGridView.DataBind()
            End If
        End Sub

     

    Hopefully this helps someone out there as much as this forum posting helped me!

     

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-10-2007, 6:51 PM
    Locked
    • Member
      6 point Member
    • Mr Blue Coat
    • Member since 05-09-2007, 7:57 PM
    • Posts 4

    For some reason, this forum tool replaced the word "E x p r e s s i o n" with "BLOCKED E X P R E S S I O N" above (remove spaces between letters).

  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-13-2007, 11:48 AM
    Locked
    • Member
      17 point Member
    • ajrich
    • Member since 11-21-2002, 4:15 PM
    • Posts 4

    Hi, thanks for the post.  Although I was never able to get this working without manually changing the sort direction between postbacks (for some reason it would always stay ascending) I did think of a different approach to this problem that worked for me.

    One problem I have with this is that felt so...DataGrid-y.  I disliked the cumbersome work needed for paging and sorting on the 1.0/1.1 DataGrid and was thrilled to see that the GridView dealt with those problem inside of it's "Black Box".  So, after hours trying to get manual sorting things to work in a clean manner I thought maybe I could trick it into thinking my on-the-fly data source is just a standard sortable/pagable datasource (datatable, datagrid or dataview). 

    What I did is create a class, as explained in an example on msdn, that has an attribute explaining that the shared method is the Select statement to be used for the object data source.  Here's a snippit of the code I used.

    Namespace IB
        ''' <summary>
        ''' Class writen to bind to the object data source.  I need to do this so that I can dynamically change the data based on the filters chosen via the dropdowns
        ''' </summary>
        ''' <remarks></remarks>
        <ComponentModel.DataObject(True)> _
        Public Class FilteredDataManager
            <ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select)> _
            Public Shared Function GetFilteredNewsData() As DataView
                Dim dt As DataTable = Nothing
                
                Try
                    Using cm As New Baird.Internet.ContentManagers.CMSNewsContentManager
                        dt = cm.GetNewsData()
                    End Using
    	'<Custom filtering based on selections on drop downs performed here>
                Catch ex As Exception
                    Throw New ApplicationException(String.Format("IB.FilteredDataManager.GetFilteredNewsData: Error {0}{1}", vbCrLf, ex.ToString()))
                End Try
    
                Return dt
            End Function
        End Class
    End Namespace

    Now that you have this class you can set this as the source to your ObjectDataSource as so (you can do this in code on even in design mode):   
    <asp:GridView ID="GridView" runat="server" AutoGenerateColumns="False" DataKeyNames="NewsLinkID" AllowSorting="True" HeaderStyle-HorizontalAlign="left" GridLines="none" Width="100%" DataSourceID="ObjectDataSourceNewsData"
    <asp:ObjectDataSource ID="ObjectDataSourceNewsData" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetFilteredNewsData" TypeName="UI.News.IB.FilteredDataManager"></asp:ObjectDataSource>
    As long as you return a DataSet, DataTable or DataView, the GridView handles sorting and paging automagically - which is how I like it.

    Hope this helps someone that has a similar issue as I.

    Thanks.
  • Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource

    07-25-2007, 4:31 AM
    Locked
    • Member
      4 point Member
    • osmanmz
    • Member since 07-25-2007, 8:01 AM
    • Posts 2

    Thanks for the post its helped a great deal.

    How is it that your page does an auto postback on sorting or paging.

     I'm using the following code which is very similar,  it does the sorting or paging only when I click a button on the page, not when I sort or page.

     i.e. it is a delayed reaction.  I've also had to add the an invalid postback or call argument error with the suggestion of setting

    EnableEventValidation="false" which resolves that issue:

    The only difference is that I've using a Master page.

    Please have a look at my code below, I've attached the code for the GridView.

    Thanks and regards

    Mohamed

    <%@ Page Language="C#" MasterPageFile="~/ShareX.master" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="BrokerDailyTrade.aspx.cs" Inherits="ShareXIntranet.BrokerDailyTradeForm" %>

    <%@ mastertype virtualpath="~/ShareX.master" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    ...

    <asp:GridView id="gridViewBrokerDailyTrade" runat="server" AutoGenerateColumns="false" DataKeyNames="ipkBrokerDailyTradeID"

    OnSelectedIndexChanged="gridViewBrokerDailyTrade_SelectedIndexChanged" AllowPaging="true" AllowSorting="true"

    OnPageIndexChanging="gridViewBrokerDailyTrade_PageIndexChanging" OnSorting="gridViewBrokerDailyTrade_Sorting"

    PagerSettings-Mode="NumericFirstLast" PageSize="25"

    >

    <Columns>

    <asp:BoundField ReadOnly="True" DataField="ipkBrokerDailyTradeID" HeaderText="ipkTransactionTradeDetailID" Visible="False"></asp:BoundField>

    <asp:BoundField DataField="dtTrade" HeaderText="Trade date" DataFormatString="{0:dd MMM yyyy}" HtmlEncode="False" SortExpression="dtTrade"></asp:BoundField>

    <asp:BoundField DataField="dYieldAmount" HeaderText="Yield amount" DataFormatString="{0:C}" HtmlEncode="False" SortExpression="dYieldAmount"></asp:BoundField>

    <asp:BoundField DataField="dtYieldAmountPaid" HeaderText="Paid date" DataFormatString="{0:dd MMM yyyy}" HtmlEncode="False" SortExpression="dtYieldAmountPaid"></asp:BoundField>

    <asp:ButtonField Text="Select" CommandName="Select" />

    </Columns>

    <EmptyDataTemplate>

    <asp:Label id="lblGridNoData" runat="server" Text="There are no broker daily trades awaiting processing." ForeColor="Red" Font-Bold="True"></asp:Label>

    </EmptyDataTemplate>

    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"></asp:SqlDataSource>

    <!--<asp:BoundField DataField="exCustom_BrokerName" HeaderText="Broker"></asp:BoundField>-->

Page 12 of 13 (186 items) « First ... < Previous 9 10 11 12 13 Next >