string percentage = e.Row.Cells[7].Text;
I am trying to do some dynamic stuff with my GridView, so I have wired up some code to the RowDataBound ev
I had a similar question, but found the solution through a slightly different approach. Instead of looking up the control as Chris suggested, I first changed the way the field was specified in the .aspx page. Instead of using a
tag, I changed the field in question to use
. Then, when I got to the RowDataBound event, the data could be accessed in the cell directly.
The relevant fragments: First, the aspx page:
...Other fields...
...
Then in the RowDataBound event I can access the values directly:
protected void gvVarianceReport_Sorting(object sender, GridViewSortEventArgs e)
{
if (e.Row.Cells[2].Text == "0")
{
e.Row.Cells[2].Text = "N/A";
e.Row.Cells[3].Text = "N/A";
e.Row.Cells[4].Text = "N/A";
}
}
If someone could comment on why this works, I'd appreciate it. I don't fully understand why without the BoundField the value is not in the cell after the bind, but you have to look it up via the control.