How can change the sort direction on a GridView column? I want to be able to just click on a gridview column header to change the sort direction. Right now it will only sort asc.
Col1 Col2 Col3 ---> I want to be able to sort the column.
2 331 900.00
3 333 940.00
<asp:GridView ID="dgd_Alerts" runat="server"
AllowPaging="True"
AllowSorting=true
AutoGenerateColumns="False
"
datakeynames="USER_ACCT_AL
ERT_ID,ALE
RT_TYPE_ID
,ALERT_OPE
R_ID"
BackColor="#CCCCCC"
OnRowCancelingEdit="Row_Ca
ncel"
OnPageIndexChanging="gridV
iew_PageIn
dexChangin
g"
OnRowCommand="Row_Selected
"
onrowupdated="Row_Updated"
OnRowEditing="Row_Editing"
OnRowUpdating="Row_Updatin
g"
OnRowDeleting="RowDeleting
"
onsorting="GridView_Sortin
g"
PagerStyle-CssClass="Pager
RowStyle"
PagerSettings-Mode="Numeri
cFirstLast
"
PagerSettings-PageButtonCo
unt="5"
Width="476px"
AutoGenerateEditButton="Tr
ue"
AutoGenerateDeleteButton="
True" >
<Columns>
<asp:BoundField DataField="ALERT_TYPE_TEXT
" SortExpression="ALERT_TYPE
_TEXT" HeaderText="Type" ReadOnly=True/>
<asp:BoundField DataField="ALERT_OPER_TEXT
" SortExpression="ALERT_OPER
_TEXT" HeaderText="Operator" ReadOnly=True/>
<asp:TemplateField HeaderText="Threshold" SortExpression="ALERT_THRE
SHOLD_AMT"
>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ALERT_THRESHOLD_AMT"
) %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ALERT_THRESHOLD_AMT"
) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="USER_ACCT_ALERT
_ID" Visible="False" />
<asp:BoundField DataField="ALERT_TYPE_ID" Visible="False" />
<asp:BoundField DataField="ALERT_OPER_ID" Visible="False" />
</Columns>
<HeaderStyle BackColor=Black />
<PagerSettings Mode="NumericFirstLast" PageButtonCount="5" />
<PagerStyle CssClass="PagerRowStyle" />
</asp:GridView>
protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
GetViewState();
if (dsAlertCriteria != null)
{
DataView dataView = new DataView(dsAlertCriteria);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(
e.SortDire
ction);
dgd_Alerts.DataSource = dataView;
dgd_Alerts.DataBind();
}
}
Start Free Trial