DataView Sorting with Paging Question

Discussion in 'ASP .Net' started by Patrick Olurotimi Ige, Dec 9, 2004.

  1. I have a DataView sorting below with DataGrid and Dataset.
    When i try implementing default Paging with the DataGrid it gives error
    when i want to SORT:-

    Error:-
    "CurrentPageIndex value. It must be >= 0 and < the PageCount. "

    CAN ANYBODY FORWARD ME AN EXAMPLE WHERE I CAN SORT THE TABLE AND AT THE
    SAME TIME PAGE!
    Thanks!


    I have the code below:-

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not IsPostBack Then
    With ddlAlpha
    .Items.Add("A")
    .Items.Add("B")
    .Items.Add("C")
    .Items.Add("D")
    .Items.Add("E")
    .Items.Add("F")
    .Items.Add("G")
    .Items.Add("H")
    End With
    End If

    Dim objConn As SqlConnection
    Dim strSql As String

    strSql = "SELECT CompanyName, ContactName, ContactTitle, Phone "
    _
    & "FROM Customers"
    objConn = New
    SqlConnection(ConfigurationSettings.AppSettings("Northwind"))

    Dim sdaCust As New SqlDataAdapter(strSql, objConn)
    Dim dstCust As New DataSet

    sdaCust.Fill(dstCust, "Customers")

    Dim dtbCust As DataTable = dstCust.Tables(0)
    Dim dtvCust As New DataView(dtbCust)


    dtvCust.RowFilter = "CompanyName LIKE '" &
    ddlAlpha.SelectedValue.ToString & "%'"



    dtvCust.Sort = "ContactName"
    dtgCust.DataSource = dtvCust
    dtgCust.DataBind()


    End Sub


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Patrick Olurotimi Ige, Dec 9, 2004
    #1
    1. Advertising

  2. Yes, here's an example for you:
    http://msdn.microsoft.com/library/d...en-us/dnaspp/html/aspnet-pageablesortable.asp

    Or you could just use this free SuperDataGrid control which takes care all
    of that tedious stuff automatically:
    http://superexpert.com/default.aspx?id=427

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net




    "Patrick Olurotimi Ige" <> wrote in message
    news:...
    >I have a DataView sorting below with DataGrid and Dataset.
    > When i try implementing default Paging with the DataGrid it gives error
    > when i want to SORT:-
    >
    > Error:-
    > "CurrentPageIndex value. It must be >= 0 and < the PageCount. "
    >
    > CAN ANYBODY FORWARD ME AN EXAMPLE WHERE I CAN SORT THE TABLE AND AT THE
    > SAME TIME PAGE!
    > Thanks!
    >
    >
    > I have the code below:-
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > If Not IsPostBack Then
    > With ddlAlpha
    > .Items.Add("A")
    > .Items.Add("B")
    > .Items.Add("C")
    > .Items.Add("D")
    > .Items.Add("E")
    > .Items.Add("F")
    > .Items.Add("G")
    > .Items.Add("H")
    > End With
    > End If
    >
    > Dim objConn As SqlConnection
    > Dim strSql As String
    >
    > strSql = "SELECT CompanyName, ContactName, ContactTitle, Phone "
    > _
    > & "FROM Customers"
    > objConn = New
    > SqlConnection(ConfigurationSettings.AppSettings("Northwind"))
    >
    > Dim sdaCust As New SqlDataAdapter(strSql, objConn)
    > Dim dstCust As New DataSet
    >
    > sdaCust.Fill(dstCust, "Customers")
    >
    > Dim dtbCust As DataTable = dstCust.Tables(0)
    > Dim dtvCust As New DataView(dtbCust)
    >
    >
    > dtvCust.RowFilter = "CompanyName LIKE '" &
    > ddlAlpha.SelectedValue.ToString & "%'"
    >
    >
    >
    > dtvCust.Sort = "ContactName"
    > dtgCust.DataSource = dtvCust
    > dtgCust.DataBind()
    >
    >
    > End Sub
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Steve C. Orr [MVP, MCSD], Dec 9, 2004
    #2
    1. Advertising

  3. Hi Steve,
    Thanks for the LINKS.
    Will have a look at that!
    Patrick



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Patrick Olurotimi Ige, Dec 9, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Saunders

    Re: alpha numeric sorting for dataview

    John Saunders, Jul 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,694
    John Saunders
    Jul 20, 2004
  2. =?Utf-8?B?U3VuZWV0?=

    Sorting a dataview

    =?Utf-8?B?U3VuZWV0?=, Aug 10, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    11,961
    Duron
    Aug 10, 2004
  3. CodeMonkey
    Replies:
    1
    Views:
    727
    joyal jhaveri
    Feb 4, 2011
  4. Paul Aspinall

    Paging..... DataSet, DataReader or DataView??

    Paul Aspinall, Jul 19, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    233
    Paul Aspinall
    Jul 19, 2003
  5. Michelle
    Replies:
    1
    Views:
    240
    Elton Wang
    Apr 8, 2005
Loading...

Share This Page