Gridview Sorting with AutoGenerateColumns OFF

  • Thread starter Thread starter Terry Olsen
  • Start date Start date
T

Terry Olsen

When I let the GridView automatically generate columns, I can allow
sorting. But when I turn autogenerate columns off, it won't allow
sorting (column names are not hyperlinks).

Is there a way I can turn sorting on when i'm not autogenerating
columns?
 
You can programmatically alter a GridView.


bool addSort = true;

BoundField currentBF = new BoundField();
currentBF.DataField = "LastName";
currentBF.HeaderText = "Employee Last Name";
if (addSort)
{
currentBF.SortExpression = "LastName";
}
gv.Columns.Add(currentBF);



Be careful with the postback .
 
Back
Top