hi
The following questions all refer to the EnsureValidSortExpression method ( page 397 ):
a) I assume the reason we replace substring
âtitleâ with
âtbh_posts.titleâ is so that SQL server processing our query doesnât get confused whether we are referring to
tbh_Forums.Title or to
tbh_Post.Title column:
Code:
if (sortExpr.StartsWith("title"))
sortExpr = sortExpr.Replace("title", "tbh_posts.title");
b) For each of the GridViewâs columns that enable sorting,
EnsureValidSortExpression method checks whether supplied
sortExpression parameter equals to one of three kinds of strings
à âcolumn_nameâ or
âcolumn_name descâ or
âcolumn_name ascâ. GridView automatically appends
âASC" or
âDESCâ to a
âcolumn_nameâ, so I donât see the point in
EnsureValidSortExpression also checking whether supplied parameter equals to
âcolumn_nameâ type of string, since as far as I know,
sortExpression string will always also contain
âASCâ or
âDESCâ value?! Thus, wouldnât the following code be just as efficient:
Code:
protected virtual string EnsureValidSortExpression(string sortExpression)
{
...
if (!sortExpr.Equals("lastpostdate asc") && !sortExpr.Equals("lastpostdate desc") &&
!sortExpr.Equals("viewcount asc") && !sortExpr.Equals("viewcount desc") &&
!sortExpr.Equals("replycount asc") && !sortExpr.Equals("replycount desc") &&
!sortExpr.Equals("addeddate asc") && !sortExpr.Equals("addeddate desc") &&
!sortExpr.Equals("addedby asc") && !sortExpr.Equals("addedby desc") &&
!sortExpr.Equals("title asc") && !sortExpr.Equals("title desc") &&
!sortExpr.Equals("lastpostby asc") && !sortExpr.Equals("lastpostby desc"))
{
sortExpr = "lastpostdate desc";
}
...
thanx