Problem with Sorting datagrid .. help please

Discussion in 'ASP .Net Datagrid Control' started by Burak, May 13, 2004.

  1. Burak

    Burak Guest

    Hello,

    I have a datagrid as follows

    <asp:datagrid id="dtgIncomplete" Runat="server"
    OnPageIndexChanged="PageActiveRecords" AllowPaging="True"
    PageSize="25" autogeneratecolumns="false" Width="537px"
    AllowSorting="True" OnSortCommand="SortCommand_OnClick">

    <Columns>
    <asp:BoundColumn HeaderText="VJC Ref#" SortExpression="JOB_ID"
    DataField="JOB_ID" HeaderStyle-HorizontalAlign="Center"
    ItemStyle-HorizontalAlign="Center"></asp:BoundColumn>

    <asp:BoundColumn HeaderText="Company Job ID"
    SortExpression="EMPLOYERS_JOB_ID" DataField="EMPLOYERS_JOB_ID"
    HeaderStyle-HorizontalAlign="Center"
    etc..
    </Columns>
    </asp:datagrid>

    and here is my sort function

    Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
    System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    dtgIncomplete.SortCommand

    GetActiveJobs(dtgIncomplete.CurrentPageIndex, e.SortExpression)
    End Sub


    Sub GetActiveJobs(ByVal index As Integer, Optional ByVal strSort As
    String = "")

    Dim Source As DataView = ds.Tables(0).DefaultView
    If strSort = "" Then
    Source.Sort = "job_id"
    Else
    Source.Sort = strSort
    End If

    'bind the data source
    dtgIncomplete.DataSource = Source
    dtgIncomplete.CurrentPageIndex = index
    dtgIncomplete.PageSize = lstDisplay.SelectedValue
    dtgIncomplete.DataBind()

    End Sub

    When I click on the header columns in the datagrid, it only does an
    ascending sort.

    How can I have it do both ascending and descending?

    Thank you,

    Burak
     
    Burak, May 13, 2004
    #1
    1. Advertising

  2. Scott Mitchell [MVP], May 13, 2004
    #2
    1. Advertising

  3. Check out this article,
    http://www.dotnetbips.com/displayarticle.aspx?id=7

    --
    Saravana
    Microsoft MVP - ASP.NET
    www.extremeexperts.com



    "Burak" <> wrote in message
    news:...
    > Hello,
    >
    > I have a datagrid as follows
    >
    > <asp:datagrid id="dtgIncomplete" Runat="server"
    > OnPageIndexChanged="PageActiveRecords" AllowPaging="True"
    > PageSize="25" autogeneratecolumns="false" Width="537px"
    > AllowSorting="True" OnSortCommand="SortCommand_OnClick">
    >
    > <Columns>
    > <asp:BoundColumn HeaderText="VJC Ref#" SortExpression="JOB_ID"
    > DataField="JOB_ID" HeaderStyle-HorizontalAlign="Center"
    > ItemStyle-HorizontalAlign="Center"></asp:BoundColumn>
    >
    > <asp:BoundColumn HeaderText="Company Job ID"
    > SortExpression="EMPLOYERS_JOB_ID" DataField="EMPLOYERS_JOB_ID"
    > HeaderStyle-HorizontalAlign="Center"
    > etc..
    > </Columns>
    > </asp:datagrid>
    >
    > and here is my sort function
    >
    > Sub SortCommand_OnClick(ByVal source As Object, ByVal e As
    > System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    > dtgIncomplete.SortCommand
    >
    > GetActiveJobs(dtgIncomplete.CurrentPageIndex, e.SortExpression)
    > End Sub
    >
    >
    > Sub GetActiveJobs(ByVal index As Integer, Optional ByVal strSort As
    > String = "")
    >
    > Dim Source As DataView = ds.Tables(0).DefaultView
    > If strSort = "" Then
    > Source.Sort = "job_id"
    > Else
    > Source.Sort = strSort
    > End If
    >
    > 'bind the data source
    > dtgIncomplete.DataSource = Source
    > dtgIncomplete.CurrentPageIndex = index
    > dtgIncomplete.PageSize = lstDisplay.SelectedValue
    > dtgIncomplete.DataBind()
    >
    > End Sub
    >
    > When I click on the header columns in the datagrid, it only does an
    > ascending sort.
    >
    > How can I have it do both ascending and descending?
    >
    > Thank you,
    >
    > Burak
     
    Saravana [MVP], May 14, 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. Replies:
    4
    Views:
    568
    Chris Uppal
    May 5, 2005
  2. KK
    Replies:
    2
    Views:
    727
    Big Brian
    Oct 14, 2003
  3. MuZZy
    Replies:
    7
    Views:
    1,830
    Mike Hewson
    Jan 7, 2005
  4. Replies:
    12
    Views:
    561
    CBFalconer
    Oct 23, 2007
  5. AlainCD
    Replies:
    0
    Views:
    215
    AlainCD
    Jan 12, 2006
Loading...

Share This Page