Gridview Sorting with AutoGenerateColumns OFF

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?
 
S

sloan

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 .
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top