<pre><code>string percentage = e.Row.Cells[7].Text;
</code></pre>

<p>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. </p>

<p>Any ideas?</p>

<p>To clarify, here is a bit the offending cell:</p>

<pre><code>&lt;asp:TemplateField HeaderText="# Percentage click throughs"&gt;
&lt;ItemTemplate&gt;
    &lt;%# AddPercentClickThroughs((int)Eval("EmailSummary.pLinksClicked"), (int)Eval("NumberOfSends")) %&gt;
&lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
</code></pre>

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

First you need to wrap your code in a
```
Label
```
or
```
Literal
```
control so that you can reference it properly. What's happening is that there's no way for the system to keep track of it, because there's no control associated with the text. It's the control's responsibility to add its contents to viewstate.
You need to use gridView.FindControl("controlName"); to get the control in the row. From there you can get at its properties including
```
Text
```
.
You can also get at the DataItem property of the Row in question and cast it to the appropriate type and extract the information directly.