//Sorting enable and generate event
<asp:GridView runat="server" ID="grvPaymentsList" EnableViewState="true" AutoGenerateColumns="false" OnSorting="grvAcceptDDPaymentsList_Sorting" AllowSorting="true" ShowFooter="true" OnRowDataBound="grvAcceptDDPaymentsList_RowDataBound">
//Define Column
<asp:TemplateField HeaderText="Payment Date" SortExpression="ApplicationDate">
<ItemTemplate>
<asp:Label Text='<%# Eval("ApplicationDate") %>' ID="lblApplicationDate" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
//OnPageLoad
//Fill ViewState
ViewState["dt"] = dt;
protected void grvAcceptDDPaymentsList_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
SetSortDirection(SortDireaction);
DataTable dataTable = (DataTable)ViewState["dt"];
if (dataTable != null)
{
//Sort the data.
dataTable.DefaultView.Sort = e.SortExpression + " " + _sortDirection;
grvAcceptDDPaymentsList.DataSource = dataTable;
grvAcceptDDPaymentsList.DataBind();
SortDireaction = _sortDirection;
}
}
catch (Exception ex)
{
ShowMessage(ex.Message, "E");
}
}
private void SetSortDirection(object SortDireaction)
{
if (sortDirection == "ASC")
{
_sortDirection = "DESC";
}
else
{
_sortDirection = "ASC";
}
}
public string _sortDirection { get; set; }
public string sortDirection { get; set; }
public string SortDireaction { get; set; }
<asp:GridView runat="server" ID="grvPaymentsList" EnableViewState="true" AutoGenerateColumns="false" OnSorting="grvAcceptDDPaymentsList_Sorting" AllowSorting="true" ShowFooter="true" OnRowDataBound="grvAcceptDDPaymentsList_RowDataBound">
//Define Column
<asp:TemplateField HeaderText="Payment Date" SortExpression="ApplicationDate">
<ItemTemplate>
<asp:Label Text='<%# Eval("ApplicationDate") %>' ID="lblApplicationDate" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
//OnPageLoad
//Fill ViewState
ViewState["dt"] = dt;
protected void grvAcceptDDPaymentsList_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
SetSortDirection(SortDireaction);
DataTable dataTable = (DataTable)ViewState["dt"];
if (dataTable != null)
{
//Sort the data.
dataTable.DefaultView.Sort = e.SortExpression + " " + _sortDirection;
grvAcceptDDPaymentsList.DataSource = dataTable;
grvAcceptDDPaymentsList.DataBind();
SortDireaction = _sortDirection;
}
}
catch (Exception ex)
{
ShowMessage(ex.Message, "E");
}
}
private void SetSortDirection(object SortDireaction)
{
if (sortDirection == "ASC")
{
_sortDirection = "DESC";
}
else
{
_sortDirection = "ASC";
}
}
public string _sortDirection { get; set; }
public string sortDirection { get; set; }
public string SortDireaction { get; set; }
No comments:
Post a Comment