Hi
I have below Gridview with AutoGenerateColumns = True. I want to sort on Date column
<%--OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit" OnRowUpdating="OnRowUpdating" AutoGenerateEditButton="true"--%>
DataTable BookPlanningResult = sQLUtility.GeBookPlanningRecommendation(vRpl, BookCollection, StudentCollection).Tables[0];
if (BookPlanningResult != null)
{
DataColumn Remarks = new DataColumn("Remarks", typeof(string));
BookPlanningResult.Columns.Add(Remarks);
DataColumn Dates = new DataColumn("Date", typeof(DateTime));
BookPlanningResult.Columns.Add(Dates);
grdPlanning.DataSource = BookPlanningResult;
int lastColumnIndex = BookPlanningResult.Columns.Count - 1;
grdPlanning.DataBind();
}
Thanks
Naimish MakwanaPosted May 1, 2023, 4:57 AM
To enable sorting on the "Date" column of your GridView, you need to set the
SortExpressionproperty of the column to "Date" and also set theAllowSortingproperty of the GridView to "true". You can do this in thegrdPlanning_RowDataBoundevent handler after the GridView has been bound to the data source, like this:Thanks
Amit MohantyPosted May 1, 2023, 4:31 AM
To sort the grid view on the Date column, you need to set the SortExpression property of the BoundField or TemplateField column that corresponds to the Date column.