Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi......

How to add button control in grid view where columns generated automatic in asp.net.I am trying to create grid user control allow data sorting and filtering, in which i am binding dataset to grid where columns are autogenerated.I want to add small 2 buttons or images in header for up and down arrow for sorting.but i am not able to do.provide solution for this to generate dynamic grid with buttons to asc and desc sorting.thanx
Posted

1 solution

Lets say, you need to sort 2nd 3rd and 4th column in your gridView... After you populate gridview do the following.

C#
gridview.Columns.Clear();
gridview.DataSource = somedatasource;
gridview.AutoGenerateColumns = true;
if (this.gridview.Rows.Count > 0)
{
gridview.Columns[1].SortMode = gridview.Columns[2].SortMode =   gridview.Columns[3].SortMode = DataGridViewColumnSortMode.Automatic;
gridview.Sort(gridview.Columns[1], ListSortDirection.Ascending); //This will put a sort indicator on 2nd column on gridview, and obviously sorted too..
}
 
Share this answer
 
v3

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