I have a gridview which is defined as follows:
<asp:GridView ID="ComponentGridView" runat="server" AutoGenerateColumns="true" OnPageIndexChanging="ComponentGridView_PageIndexChanging" OnSorting="ComponentGridView_Sorting">
</asp:GridView>
and these are the methods that get invoked on ComponentGridView_Sorting
protected void ComponentGridView_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dataTable = ComponentGridView.DataSource as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirection(e.SortDirection);
ComponentGridView.DataSource = dataView;
ComponentGridView.DataBind();
}
}
and
private string ConvertSortDirection(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
return newSortDirection;
}
But it seems like nothing is happening when i click on the column headers.
What am i doing wrong ?
Please help me
Thanks in anticipation
When i debugged the dataTable is null
DataTable dataTable = ComponentGridView.DataSource as DataTable;