execute code when select is clicked in GridView
<p>I have a GridView and a select link in the GrdiView, when the item is selected I want it to read the contents to a textbox below the GridView. The only way I can think is by accessing the behind code for the onClick function of the select link. The problem is I am unsure how to do this.</p>

<p>UPDATED jams method:</p>

<p>C# code</p>

<pre><code>protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
    GridView1.SelectedIndex = e.NewSelectedIndex;
    TextBox1.Text = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
}
</code></pre>

<p>front code</p>

<pre><code>&lt;asp:GridView ID="GridView1" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" 
GridLines="None"&gt;
</code></pre>

<p>UPDATE my method:</p>

<pre><code>protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
    int i = GridView1.SelectedIndex;
    ds.Tables["Comments"].Rows[i]["Comment"] = TextBox1.Text;
}
</code></pre>

<p>also tried this but I get an error -> System.IndexOutOfRangeException: There is no row at position -1.</p>

<p>Thanks.</p>
