sort columns of gridview in asp.net c#

前端 未结 7 433
别那么骄傲
别那么骄傲 2020-12-17 00:43

Can anyone tell the function to sort the columns of a gridview in c# asp.net.

The databound to gridview is from datacontext created using linq. I wanted to click th

7条回答
  •  悲哀的现实
    2020-12-17 01:15

    In Half Pseudocode for SQL Query

    string Query= string.Empty;
    string SortExpression = string.Empty;
    
    // HDFSort is an HiddenField !!!
    
    protected void SortCommand_OnClick(object sender, GridViewSortEventArgs e)
    {
       SortExpression = e.SortExpression; 
       Query = YourQuery + " ORDER BY "+SortExpression +" "+ HDFSort.Value ;
       HDFSort.Value = HDFSort.Value== "ASC" ? "DESC" : "ASC";
       RefreshGridView();
    }
    
    protected void RefreshGridView()
    {
       GridView1.DataSource = DBObject.GetData(Query);
       GridView1.DataBind();
    }
    

提交回复
热议问题