C# – Getting value from a cell from a gridview on RowDataBound event


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 event. I am trying to get the value from a particular cell, which is a TemplateField. But the code above always seems to be returning an empty string.

Any ideas?

To clarify, here is a bit the offending cell:

<asp:TemplateField HeaderText="# Percentage click throughs">
    <%# AddPercentClickThroughs((int)Eval("EmailSummary.pLinksClicked"), (int)Eval("NumberOfSends")) %>

On a related note, does anyone know if there is a better way of selecting the cell in the row. It sucks putting in cell[1]. Couldn't I do cell["mycellname"], so if I decide to change the order of my cells, bugs wont appear?

Best Solution

why not pull the data directly out of the data source.

DataBinder.Eval(e.Row.DataItem, "ColumnName")
Related Question