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

I have a web grid with 5 columns designed like
<asp:BoundField DataField="COUNTRY_NAME" HeaderText="Country Name" SortExpression="COUNTRY_NAME" />

i am trying to add sort icons whenever user clicks on column header on sorting event.

int i =0;
foreach (DataGridColumn col in GridView.Columns)
{
if (col.SortExpression == e.SortExpression)
CustomersGridView.Columns[i].HeaderStyle.CssClass = "gridHeaderSort";
i++;
}

while doing am getting error :
Unable to cast object of type 'System.Web.UI.WebControls.BoundField' to type 'System.Web.UI.WebControls.DataGridColumn'.


Please Help.

Regards, Kiruba
Posted

1 solution

You're using the DataGrid control[^], which uses BoundColumn[^] instead of BoundField[^].

If you want to continue using the DataGrid class, you'll need to replace <asp:BoundField .../> with <BoundColumn ...>. Alternatively, you could switch to using the newer GridView control[^] instead.
 
Share this answer
 

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