I have a method
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();
}
and it's starting to smell, bad. I have 4 columns that I have to sort on. I'd like to avoid doing a switch or something to determine which property on the CustomerSet I'm trying to order. What would a better programmer do to associate the SortExpression, which is a string, to the property on one of my CustomerSet objects?
Thanks as always.
Jim