tengo un métodoClasificación de Gridview con Entity Framework.
private void BindGrid()
{
dataContext = new VTCEntities();
string SortExpression = "DisplayName";
string SortDirection = "ASC";
int skip = 0;
if (this.ViewState["SortExp"] != null)
{
SortExpression = this.ViewState["SortExp"].ToString();
}
if (this.ViewState["SortOrder"] != null)
{
string d = this.ViewState["SortOrder"].ToString();
if (d == "ASC")
{
SortDirection = "ASC";
}
else
{
SortDirection = "DESC";
}
}
if (CurrentPage != 0)
{
skip = CurrentPage * PageSize;
}
if (SortDirection == "ASC")
{
this.grdCustomers.DataSource = dataContext.CustomerSet.OrderBy(i => i.DisplayName).Skip(skip).Take(PageSize);
}
else
{
this.grdCustomers.DataSource = dataContext.CustomerSet.OrderByDescending(i => i.DisplayName).Skip(skip).Take(PageSize);
}
this.grdCustomers.DataBind();
}
y está empezando a oler, malo. Tengo 4 columnas que tengo que ordenar. Me gustaría evitar hacer un cambio o algo para determinar qué propiedad en el CustomerSet estoy tratando de ordenar. ¿Qué haría un mejor programador para asociar SortExpression, que es una cadena, a la propiedad en uno de mis objetos CustomerSet?
Gracias como siempre.
Jim
bendewey, usted es tan dinero que ni siquiera sabe cómo es el dinero que usted es ... muchas gracias por el empuje en la dirección correcta. – jim
esa es una gran solución. Gracias. –