Using asp:GridView to populate a form
<p>I am using an asp gridview element to do a search on the database and return some data using </p>

<pre><code>    &lt;asp:GridView ID="storedRecordsGrid" AutoGenerateSelectButton="true"  emptydatatext="No data    available." runat="server"&gt;
</code></pre>

<p>So i have a gridview that gets popolated and each row has its own select event. When the user selects a row I want to use the data in that row to populate texboxes on my page. </p>

<pre><code>    protected void OnRowCommand(GridViewCommandEventArgs e)
        { 

        }
</code></pre>

<p>So I have this method and i have my textboxes but when the select even fires I am not sure how the data is stored for each colums of that selected row. what i want to have is something like.</p>

<pre><code>    protected void OnRowCommand(GridViewCommandEventArgs e)
        { 
         mytextbox.text=datagridcolumn.value   
        }
</code></pre>

<p>I am using .net 2.0 
and my c# code as of right now looks like this. </p>

<pre><code>private DataTable fillGrid(string dComplainantFName,string dComplainantlName)
   {
        string server = "";
        using (SqlConnection cnx = new SqlConnection(server))
        using (SqlCommand cmd = new SqlCommand("ComplaintReportLookUp", cnx) { CommandType = CommandType.StoredProcedure })
        using (DataTable dt = new DataTable())
        {
            cmd.Parameters.AddWithValue("@fName", dComplainantFName);
            cmd.Parameters.AddWithValue("@lName", dComplainantlName);
            try
            {
                cnx.Open();
                dt.Load(cmd.ExecuteReader());
                cnx.Close();
                return dt;
            }
            catch (Exception ex)
            {
                throw new Exception("Error executing MyProcedureName.", ex);
            }
        }

    }
   protected void executeGrid(object sender, EventArgs e)
        {
            storedRecordsGrid.DataSource = this.fillGrid(dComplainantFName.Text,dComplainantLName.Text);
            storedRecordsGrid.DataBind();
        }
    protected void OnRowCommand(GridViewCommandEventArgs e)
        { 

        } 
</code></pre>

<p>Thank you for your help</p>

<hr>

<p>Thanks Tim for the help this is what ended up working for me. </p>

<pre><code>    protected void gridSelectedIndexChanged(Object sender, EventArgs e)
    {
    var row = ((GridView)sender).SelectedRow;
    //var cell1Text = row.Cells[0].Text; // should be your autogenerated select cell 
    dComplainantFName.Text = row.Cells[1].Text.Replace("&amp;nbsp;", ""); // Text in column 1 (the first column of your DataTable) 
    dComplainantLName.Text = row.Cells[2].Text.Replace("&amp;nbsp;", ""); // Text in column 2 (the second column of your DataTable) 
    dComplainantMName.Text = row.Cells[3].Text.Replace("&amp;nbsp;", "");
    dComplainantAddress.Text = row.Cells[4].Text.Replace("&amp;nbsp;", "");
    dComplainantCity.Text = row.Cells[5].Text.Replace("&amp;nbsp;", "");
    dComplainantState.Text = row.Cells[6].Text.Replace("&amp;nbsp;", "");
    dComplainantZip.Text = row.Cells[7].Text.Replace("&amp;nbsp;", "");
    dComplainantPhone.Text = row.Cells[8].Text.Replace("&amp;nbsp;", "");
    storedRecordsGrid.Visible = false;
    } 
</code></pre>
