Есть ли лучший способ отсортировать эту сетку данных?
Это работает, однако кажется, что его нельзя использовать повторно.
Если у вас есть идеи или более эффективные способы решения этой проблемы, пожалуйста, дайте мне знать.
Ниже приведен код. Пожалуйста, дайте мне знать, если у вас есть идеи ..
protected void grdPropMgrLeaseAgents_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = "A";
if (ViewState[e.SortExpression + "_sort"] != null)
{
sortExpression = ViewState[e.SortExpression + "_sort"].ToString();
}
List<Person> list = (List<Person>)ViewState["propertyManagersAndLeasingAgents"];
if (sortExpression == "A")
{
if (e.SortExpression == "EmpFullName") list.Sort((x, y) => string.Compare(x.EmpFullName, y.EmpFullName));
if (e.SortExpression == "FirstName") list.Sort((x, y) => string.Compare(x.FirstName, y.FirstName));
if (e.SortExpression == "LastName") list.Sort((x, y) => string.Compare(x.LastName, y.LastName));
if (e.SortExpression == "DepartmentName") list.Sort((x, y) => string.Compare(x.DepartmentName, y.DepartmentName));
if (e.SortExpression == "MarketName") list.Sort((x, y) => string.Compare(x.MarketName, y.MarketName));
if (e.SortExpression == "Title") list.Sort((x, y) => string.Compare(x.Title, y.Title));
if (e.SortExpression == "Roles") list.Sort((x, y) => string.Compare(x.Roles, y.Roles));
if (e.SortExpression == "CellPhone") list.Sort((x, y) => string.Compare(x.CellPhone, y.CellPhone));
if (e.SortExpression == "OfficePhone") list.Sort((x, y) => string.Compare(x.OfficePhone, y.OfficePhone));
if (e.SortExpression == "EmailAddress") list.Sort((x, y) => string.Compare(x.EmailAddress, y.EmailAddress));
if (e.SortExpression == "City") list.Sort((x, y) => string.Compare(x.City, y.City));
if (e.SortExpression == "State") list.Sort((x, y) => string.Compare(x.State, y.State));
if (e.SortExpression == "PropertyName") list.Sort((x, y) => string.Compare(x.PropertyName, y.PropertyName));
if (e.SortExpression == "PropertyStreet") list.Sort((x, y) => string.Compare(x.PropertyStreet, y.PropertyStreet));
if (e.SortExpression == "DisplayName") list.Sort((x, y) => string.Compare(x.DisplayName, y.DisplayName));
if (e.SortExpression == "ZipCode") list.Sort((x, y) => string.Compare(x.ZipCode, y.ZipCode));
}
else
{
if (e.SortExpression == "EmpFullName") list.Sort((y, x) => string.Compare(x.EmpFullName, y.EmpFullName));
if (e.SortExpression == "FirstName") list.Sort((y, x) => string.Compare(x.FirstName, y.FirstName));
if (e.SortExpression == "LastName") list.Sort((y, x) => string.Compare(x.LastName, y.LastName));
if (e.SortExpression == "DepartmentName") list.Sort((y, x) => string.Compare(x.DepartmentName, y.DepartmentName));
if (e.SortExpression == "MarketName") list.Sort((y, x) => string.Compare(x.MarketName, y.MarketName));
if (e.SortExpression == "Title") list.Sort((y, x) => string.Compare(x.Title, y.Title));
if (e.SortExpression == "Roles") list.Sort((y, x) => string.Compare(x.Roles, y.Roles));
if (e.SortExpression == "CellPhone") list.Sort((y, x) => string.Compare(x.CellPhone, y.CellPhone));
if (e.SortExpression == "OfficePhone") list.Sort((y, x) => string.Compare(x.OfficePhone, y.OfficePhone));
if (e.SortExpression == "EmailAddress") list.Sort((y, x) => string.Compare(x.EmailAddress, y.EmailAddress));
if (e.SortExpression == "City") list.Sort((y, x) => string.Compare(x.City, y.City));
if (e.SortExpression == "State") list.Sort((y, x) => string.Compare(x.State, y.State));
if (e.SortExpression == "PropertyName") list.Sort((y, x) => string.Compare(x.PropertyName, y.PropertyName));
if (e.SortExpression == "PropertyStreet") list.Sort((y, x) => string.Compare(x.PropertyStreet, y.PropertyStreet));
if (e.SortExpression == "DisplayName") list.Sort((y, x) => string.Compare(x.DisplayName, y.DisplayName));
if (e.SortExpression == "ZipCode") list.Sort((y, x) => string.Compare(x.ZipCode, y.ZipCode));
}
ViewState["propertyManagersAndLeasingAgents"] = list;
this.grdPropMgrLeaseAgents.DataSource = list;
this.grdPropMgrLeaseAgents.DataBind();
if (sortExpression == "A")
{
ViewState[e.SortExpression + "_sort"] = "D";
}
else
{
ViewState[e.SortExpression + "_sort"] = "A";
}
}