Grid fails to sort by column when pagging

Discussion in 'ASP .Net Datagrid Control' started by mkhmer, Apr 20, 2006.

  1. mkhmer

    mkhmer Guest

    May anyone help me that my grid always lost the memory of sorting based on a
    specific column when I clicked to move to next page index.

    My DataGrid1:
    ===============
    <asp:datagrid id="DataGrid1" runat="server" AllowSorting="True"
    AutoGenerateColumns="False" OnItemDataBound="Custom_Bound"
    HorizontalAlign="Left" GridLines="Vertical"
    BorderColor="LightGray" BackColor="White" PageSize="1" Height="70px"
    Width="601px" OnPageIndexChanged="My_Page" AllowPaging="True"
    Font-Size="X-Small" OnSortCommand="DoSortCommand">
    <HeaderStyle Font-Bold="True" ForeColor="MediumBlue"
    BackColor="Gainsboro"></HeaderStyle>
    <PagerStyle Mode="NumericPages"></PagerStyle>
    <EditItemStyle BorderColor="#404040"></EditItemStyle>
    <AlternatingItemStyle ForeColor="Black"></AlternatingItemStyle>
    <ItemStyle BorderWidth="1px" ForeColor="Black"
    BorderStyle="Solid" BorderColor="#404040"></ItemStyle>
    <Columns>
    <asp:BoundColumn .....
    <asp:BoundColumn .....
    <asp:BoundColumn .....
    <asp:BoundColumn .....
    </Columns>
    </asp:datagrid>

    The code is below:
    ================
    Dim Adp as new oledbadapter
    Dim Conn as new oledbconnection
    Dim Dset as new DataSet
    Dim Dv as new DataView
    Dim CurSortExp as string

    Sub My_Page(sender As Object, e As DataGridPageChangedEventArgs)
    if CurShortExp<>"" then dv.sort=CurShortExp
    DataGrid1.CurrentPageIndex = e.NewPageIndex
    BindGrid(true)
    end sub

    Sub Showdata
    DataGrid1.Visible=True
    DataGrid1.DataSource=dv
    if CurShortExp<>"" then dv.sort=CurShortExp
    DataGrid1.DataBind()
    End sub

    sub DoSortCommand(s as object,e as DataGridSortCommandEventArgs)
    BindGrid(true)
    CurShortExp=e.SortExpression
    dv.sort=e.SortExpression
    showdata
    end sub

    Sub BindGrid(optional PageMoved as boolean = false)
    Conn= new oledbconnection .......
    Adp= new oledbadapter......
    Adp.Fill(Dset,"mydata")
    Dv.Table=Dset.Tables("mydata")
    if Dset.Tables(0).Rows.Count>=0 then
    showdata
    else
    response.write("No record")
    end if
    Conn.Close()
    End sub

    ===================

    Thanks
    mkhmer, Apr 20, 2006
    #1
    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:
    1
    Views:
    427
    Andy Dingley
    Feb 21, 2007
  2. Protoman
    Replies:
    8
    Views:
    485
    Richard Herring
    Apr 5, 2006
  3. CFirmino
    Replies:
    1
    Views:
    135
    Alvin Bruney [MVP]
    Apr 4, 2004
  4. Navin
    Replies:
    1
    Views:
    673
    Ken Schaefer
    Sep 9, 2003
  5. Replies:
    0
    Views:
    80
Loading...

Share This Page