我在下面编写了用于排序网格视图列表的代码行
public void BindGrid()
{
hdndata.Value = "no";
EFDbContext dbContext = new EFDbContext();
MainSetting Item = dbContext.FetchMainAppSettings();
SearchHint = txtName.Text;
CountryID = new Guid(ddlCountry.SelectedValue.ToString());
City = txtCity.Text;
State = ddlState.SelectedValue.ToString();
City = txtCity.Text;
Street = "";
grdServiceList.Columns[2].HeaderText = Item.OrganisationCustomLabel+"/"+"Users";
IEnumerable<_14Muslims.Domain.Entity.Service> Services = context.ServicesFetchWithPaging(ctlPager.PageIndex, ctlPager.PageSize, SearchHint, CountryID, Street, State, City);//.OrderBy(DataGridSortBy);
grdServiceList.DataSource = Services;
grdServiceList.DataBind();
TotalRecords = 0;
foreach (_14Muslims.Domain.Entity.Service c in Services)
{
hdndata.Value = "yes";
TotalRecords = c.TotalPages;
break;
}
ctlPager.UpdatePageLables(TotalRecords);
ctlPager.Visible = TotalRecords > 0;
Services = null;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "getSelected", "HideProcessImage()", true);
}
protected void grdServiceList_Sorting(object source, GridViewSortEventArgs e)
{
SortExpression = e.SortExpression;
if (DataGridSortDirection == SortDirection.Ascending)
{
DataGridSortDirection = SortDirection.Descending;
BindGrid();
DataGridSortByDirection = "DESC";
}
else
{
DataGridSortDirection = SortDirection.Ascending;
BindGrid();
DataGridSortByDirection = "ASC";
}
DataGridSortBy = SortExpression;
}
#region Sorting
public SortDirection DataGridSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}
public string DataGridSortBy
{
get
{
if (ViewState["DataGridSortBy"] == null)
ViewState["DataGridSortBy"] = "Description";
return ViewState["DataGridSortBy"].ToString();
}
set { ViewState["DataGridSortBy"] = value; }
}
public string DataGridSortByDirection
{
get
{
if (ViewState["DataGridSortByDirection"] == null)
ViewState["DataGridSortByDirection"] = "ASC";
return ViewState["DataGridSortByDirection"].ToString();
}
set { ViewState["DataGridSortByDirection"] = value; }
}
//protected void grdPostingList_Sorting(object source, GridViewSortEventArgs e)
//{
// SortExpression = e.SortExpression;
// if (DataGridSortDirection == SortDirection.Ascending)
// {
// DataGridSortDirection = SortDirection.Descending;
// }
// else
// {
// DataGridSortDirection = SortDirection.Ascending;
// }
// BindGrid();
//}
#endregion
现在的问题是它无法正常运行,也没有显示错误信息。
它没有对列表进行排序。