How to sort a column in data grid:
How to sort a column in data grid:
I want to sort on the column "LoanNumber"
In my ASP code shown below, I added AllowSorting property to True, in the
DataGrid.Which gives me the hyperlink in the header.
In order to have this happen I need to do two things: create a
sort event handler and specify the event handler for the
DataGrid's sort event.
I created the sub SortEventHandler as below but I am lost as to
what is next to do?
Sub SortEventHandler(sender as Object, e as DataGridSortCommandEventArgs)
...
End Sub
<asp:datagrid id="DG1" runat="server" BackColor="Gainsboro" AutoGenerateColumns="false"
OnItemCommand="DGColumnBtn"
Width="512px" AllowSorting="True">
<EditItemStyle BackColor="Red"></EditItemStyle>
<AlternatingItemStyle BackColor="#C0FFFF"></AlternatingItemStyle>
<HeaderStyle BackColor="Silver"></HeaderStyle>
<AlternatingItemStyle BackColor="White" />
<Columns>
<asp:ButtonColumn Text="Details" HeaderText="Credit Life" ButtonType="PushButton" />
<asp:BoundColumn DataField="clid" Visible="False" />
<asp:BoundColumn DataField="CLMaturityDate" DataFormatString="{0:MM-dd-yyyy}" HeaderText="MAT Date" />
<asp:BoundColumn DataField="LoanNumber" HeaderText="LoanNumber" SortExpression="LoanNumber" />
<asp:BoundColumn DataField="Loanamount" HeaderText="Amount" />
</Columns>
</asp:datagrid></form>
Private Sub DG1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DG1.SelectedIndexChanged
End Sub
|