I have a gridview that I load some ticket data into. Depending on the user action, this gridview will load up different sqldatasources and redisplay the data.
Here is the markup for the gridview:
<X:GridViewX ID="gvxTaskList" runat="server"
AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
Width="100%" Height="100%" CssClass="tablestyle"
OnRowCreated="gvxTaskList_RowCreated"
OnPageIndexChanging="gvxTaskList_PageIndexChanging"
OnSorting="gvxTaskList_Sorting">
So, I have two problems.
First, the sorting event does not work at all for me. I get a null in the datatable. The code:
protected void gvxTaskList_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
System.Data.DataTable dataTable = gvxTaskList.DataSource as
System.Data.DataTable;
if (dataTable != null)
{
System.Data.DataView dataView = new System.Data.DataView(dataTable);
dataView.Sort = e.SortExpression + " " +
ConvertSortDirectionToSql(e.SortDirection);
gvxTaskList.DataSource = dataView;
gvxTaskList.DataBind();
}
}
catch (Exception ex)
{
}
}
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
try
{
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
}
catch (Exception ex)
{
}
return newSortDirection;
}
Fails at if (dataTable != null) because, well, it IS null.
Second problem is the paging. When it first loads the gridview, paging is fine. I have two pages worth of data onload. i can page back and forth all day with no errors. The problem is when I change datasources and bring back three pages of data. I try to click on page 3 immediately from the first page and it reloads the previous data (with two pages). Any help would be appreciated.