Lucas
Lucas

Reputation: 125

How to sort Gridview items

I have a dynamically created gridview in c# asp.net that I need sorted when you load the page. How can this be done? I am using gridview1.DataBind() to bind.

Upvotes: 2

Views: 647

Answers (1)

santosh singh
santosh singh

Reputation: 28652

try this

DataTable table = GetTable();
table.DefaultView.Sort = "SortCondition";

//
// Display all records in the view.
//
DataView view = table.DefaultView;

Now Bind the grid

 GridView1.DataSource=view;
 GirdView1.DataBind();

Upvotes: 1

Related Questions