嗨,我有一个网格视图,我显示了几个名为姓名、电话、信息和日期的列。我的要求是,如果我点击列标题,那么它应该被排序,我的 aspx 代码在这里......
<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>
我的代码是:
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
为此,如果我单击列标题,它应该首先按升序排序,如果我下次单击,它应该按降序排序,它应该适用于网格视图中列出的所有列...
请帮助我为此编码...