Click here to Skip to main content
11,409,450 members (55,782 online)
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 Sergey Alexandrovich Kryukov 8,676
1 OriginalGriff 6,885
2 Maciej Los 3,322
3 Abhinav S 3,238
4 Peter Leow 3,034


Advertise | Privacy | Mobile
Web03 | 2.8.150414.5 | 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