通过下拉列表和网格视图在SqlDataSource中动态排序

时间:2013-01-28 09:26:20

标签: asp.net sql sqldatasource

我有一个连接到DataSqlSource的网格视图。我想通过下拉列表动态地对查询进行排序。例如按日期,姓名,家庭等 我也在我的查询中加入了一些表格。 我在我的DataSqlSource中使用此代码:

  SELECT AddTitle.Title, SubmitManuscript.Status, AddArticleType.Type, AddArticleType.UserName, AddArticleType.ArticleType, SubmitManuscript.date, SubmitManuscript.ArticleNum, AddArticleType.ArticleID, CONVERT (VARCHAR(10), SubmitManuscript.date, 103) AS date1, OtherWritter.ArticleID AS Expr1, OtherWritter.name, OtherWritter.family, AddArticleType.CheckFinish FROM AddArticleType INNER JOIN AddTitle ON AddArticleType.ArticleID = AddTitle.ArticleID INNER JOIN SubmitManuscript ON AddArticleType.ArticleID = SubmitManuscript.ArticleID INNER JOIN OtherWritter ON AddTitle.ArticleID = OtherWritter.ArticleID WHERE (AddArticleType.ArticleID IN (SELECT ArticleID FROM AddUpload_4 AS AddUpload_4_1 WHERE (AddArticleType.CheckFinish = '0'))) AND (AddArticleType.Type = @Type) AND (SubmitManuscript.Status = 'Accept') AND 
(OtherWritter.MainAuthor = 'Yes') ORDER BY '[' + @SortOrder + ']' DESC

但它对我不起作用,也没有排序!

我也试试这段代码,这次它给了我一个错误: 这是代码:

SELECT ...
FROM ...
ORDER BY
    CASE WHEN @order=Country THEN Country  END DESC,
    CASE WHEN @order= City THEN City  END ASC,
    CASE WHEN @order= name THEN name  END ASC

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我想它应该是:

SELECT ...
FROM ...
ORDER BY
    CASE WHEN @order='Country' THEN Country  END DESC,
    CASE WHEN @order='City' THEN City  END ASC,
    CASE WHEN @order='name' THEN name  END ASC