M
mkhmer
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
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