Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi All,
 
I have created a gridview at runtime.
I want to make the columns of the gridview sortable.
 
i am adding colums to the gridview columns dynamically by using the below code
 
gv.AllowSorting = true;
 
gv.RowCreated += new GridViewRowEventHandler(gv_RowCreated);
gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound);
gv.Sorting += new GridViewSortEventHandler(gv_Sorting);
 
if (gv.Columns.Count == 0)
            {
                foreach (DataColumn col in dtUserDetails.Columns)
                {
                    TemplateField bfield = new TemplateField();
 
                    bfield.HeaderTemplate = new GridViewTemplate.GridViewTextTemplate(ListItemType.Header, col.ColumnName, col.DataType.Name);
 
                    bfield.ItemTemplate = new GridViewTemplate.GridViewTextTemplate(ListItemType.Item, col.ColumnName, col.DataType.Name);
 
                    bfield.EditItemTemplate = new GridViewTemplate.GridViewTextTemplate(ListItemType.EditItem, col.ColumnName, col.DataType.Name);
                    bfield.SortExpression = col.ColumnName;
 
                    gv.Columns.Add(bfield);
 
                }
            }
 
I have RowCreated, RowDataBound, and Sorting event handler for the gridview.
But the gridview column are not clickable for firing the sort event.
So what i need to do to make it sortable.
 
Thanks for your help in advance.
Posted 25-Jun-12 1:40am
Edited 25-Jun-12 2:06am
v2
Comments
GanesanSenthilvel at 25-Jun-12 7:06am
   
Code format

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

this.gv.Sort(this.gv.Columns["Sorted Column Name"], ListSortDirection.Descending(or) ascending);
  Permalink  

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

  Print Answers RSS
0 Peter Leow 210
1 Abhinav S 155
2 Mika Wendelius 131
3 Sergey Alexandrovich Kryukov 125
4 TheRealSteveJudge 114
0 Sergey Alexandrovich Kryukov 8,613
1 OriginalGriff 6,536
2 Peter Leow 3,727
3 Zoltán Zörgő 3,456
4 Richard MacCutchan 2,442


Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 25 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100