Click here to Skip to main content
15,886,512 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Experts,
i have a problem with Binding gridview values.. my gridview like this

SQL
1   School1    Close
2   School2    Open
3   School3    Close
4   School4    Close
5   School5    Open
6   School6    Open
7   School7    Close


how can i show Open Schools First on page load in above grid view..

Please help me..


Thanks in advance
Posted
Comments
Gihan Liyanage 4-Sep-14 6:11am    
Sort from the SQL query used for data bind..
Gihan Liyanage 4-Sep-14 6:16am    
ORDER BY [YourStatusColoumn] DESC

If You are binding DataTable then you can also try this

C#
dt.DefaultView.Sort = "StatusCol Desc"; //dt is your data table and StatusCol is your column name
grdView.DataSource = dt.DefaultView;
grdView.DataBind();
 
Share this answer
 
You can sort that particular column by 'DESC" so as per the dictionary text format it will sort the column and so the 'Open' will come first then 'Close' if it sorted in descending order.

You can use sorting either of the levels like described below :-

1) Sort it while fetching from database in query itself
ex :-
SQL
ORDER BY [StatusColoumn] DESC


2) Else you can apply default sorting for the grid on page load as below :-
ex :-
C#
protected void Page_Load(object sender, EventArgs e)
    {
        // Set your deault sort expression.
        if (String.IsNullOrEmpty(GridView1.SortExpression)) GridView1.Sort("SortExpression", SortDirection.Ascending);
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900