ASP.NET - Overriding Gridview OnRowCreated to add sort images -- columns are null
Posted
by Zach
on Stack Overflow
See other posts from Stack Overflow
or by Zach
Published on 2010-05-18T01:47:01Z
Indexed on
2010/05/18
1:50 UTC
Read the original article
Hit count: 369
I'm overriding the onrowcreated to add sort images to the header row of a gridview. This works, but actually adding a sortexpression doesn't. What I want to do is set the images as imagebuttons and set their commandarguments to the sort expression of the column they are sorting for.
I would assume I could get the cell and from it's index get the gridviewcolumn. Then, I could just get the sortexpression of the gridview column, but this does not work. The columns are null. OnRowCreated Code snippet below:
//if this is the header row, we add sort images to each cell
if (row.RowType == DataControlRowType.Header)
{
//iterate through the cells
for (int i = 0; i < row.Cells.Count; i++)
{
//if the column is sortable and visible
if (this.Columns[i].SortExpression != string.Empty && this.Columns[i].Visible)
{
string strSort = this.Columns[i].SortExpression;
}
}
}
Can we not get columns in OnRowCreated like this?
© Stack Overflow or respective owner