</asp:TemplateField>
<asp:TemplateField HeaderText="System Manager" SortExpression="sysaccount">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("sysaccount") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("sysaccount") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="syspw">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("syspw") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("syspw") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Log" SortExpression="log">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("log") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("log") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridView()
End If
End Sub
Private Sub BindGridView()
' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
Dim dt As DataTable = New DataTable()
Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
conn.Open()
da.Fill(dt)
da.Dispose()
conn.Close()
GridView1.DataSource = dt
GridView1.DataBind()
End Sub
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim dtSortTable As DataTable = TryCast(GridView1.DataSource, DataTable)
If dtSortTable IsNot Nothing Then
Dim dvSortedView As New DataView(dtSortTable)
dvSortedView.Sort = e.SortExpression + " " + getSortDirectionString(e.SortDirection)
GridView1.DataSource = dvSortedView
GridView1.DataBind()
'BindGridView()
End If
End Sub
Private Function getSortDirectionString(ByVal sortDireciton As SortDirection) As String
Dim newSortDirection As String = [String].Empty
If sortDireciton = SortDirection.Ascending Then
newSortDirection = "ASC"
Else
newSortDirection = "DESC"
End If
Return newSortDirection
End Function
This sorting is not working. How to fix? Thanks.