Hi i have a grid view in this i am displaying few columns called name, phone, information and date. My requirement is if I click on the columns header then it should be sorted, my aspx code is here...
<asp:GridView ID="sorttest" runat="server" AllowSorting="true">
<Columns>
<asp:BoundField DataField="ID" HeaderText="Sno." Visible="False" />
<asp:BoundField DataField="Name" HeaderStyle-CssClass="tdHead3" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Phone" HeaderStyle-CssClass="tdHead3" HeaderText="Phone Number" SortExpression="Phone"/>
<asp:BoundField DataField="Information" HeaderStyle-CssClass="tdHead3" HeaderText="Information Of The Offender" SortExpression="Information"/>
<asp:BoundField DataField="Date" HeaderStyle-CssClass="tdHead3" HeaderText="Date of Graffiti" SortExpression="Date"/>
</Columns>
</asp:GridView>
and my code is:
Public Sub FillGrid()
Try
myconnection = New SqlConnection(conntection string)
cmd = New SqlCommand()
cmd.CommandText = "Retrievedetails"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = myconnection
ds = New DataSet()
da = New SqlDataAdapter(cmd)
da.Fill(ds, "details")
myconnection.Open()
sorttest.DataSource = ds
sorttest.DataBind()
Catch ex As Exception
Finally
myconnection.Close()
End Try
End Sub
for this if i click on the column header it should sort first as ascending order if i click next time then it should sort in desc order it sholud apply for all the columns listed in grid view...
please help me in coding for this...
You need to handle
OnSortingevent, here is how I'm doing it:ASPX:
CodeBehind:
now in
FillGridyou need to sort the table (details) you are getting based on these values: