title: Extract Data from gridview to textboxes
body: <p>I've got a gridview that I'm trying to exctract data to populate 3 textboxes... I've tried numerous ways, but I just can't get to the right way of doing this... I've built the gridview manually, thus it does not have a "editTemplate"... Can someone please direct me in the right way to do this?
  This is how my gridview looks like:</p>
  
  <pre><code>    &lt;asp:GridView ID="GridView1" runat="server"  AllowPaging="True" 
                                  EmptyDataText="No parts has been added to the model, please add a part."
                                  BorderColor="Black" BorderStyle="Solid"  BorderWidth="2px" 
                                  CellPadding="3" onrowcommand="GridView1_RowCommand"&gt;
                                  &lt;Columns&gt;
                                  &lt;asp:TemplateField HeaderText=""&gt;
                                   &lt;ItemTemplate&gt;
                                     &lt;asp:LinkButton ID="EditButton" runat="server" CssClass="EditButton" CommandName="Edit" Text="Edit" /&gt;
                                   &lt;/ItemTemplate&gt;
                                   &lt;/asp:TemplateField&gt;
                                   &lt;asp:TemplateField HeaderText=""&gt;
                                   &lt;ItemTemplate&gt;
                                     &lt;asp:LinkButton ID="DeleteButton" runat="server" CssClass="DeleteButton" CommandName="Delete" Text="Delete" /&gt;
                                   &lt;/ItemTemplate&gt;
                                   &lt;/asp:TemplateField&gt;
                                  &lt;/Columns&gt;
                              &lt;HeaderStyle BackColor="#FFFFCC"  BorderColor="Black" BorderStyle="Solid" 
                                  BorderWidth="2px" /&gt;
                          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Then this is how I've added the necessary columns to that gridview:</p>
  
  <pre><code>     protected void Page_Load(object sender, EventArgs e)
  {
      if (!Page.IsPostBack)
      {
          dt = new DataTable();
          MakeDataTable();
          EmptyDataString();
      }
      else
      {
          dt = (DataTable)ViewState["DataTable"];
      }
      ViewState["DataTable"] = dt; 
  
  }
  
  #region GridView
  
  private void EmptyDataString()
  {
      TemplateBuilder tmpEmptyDataTemplate = new TemplateBuilder();
      tmpEmptyDataTemplate.AppendLiteralString("No parts has been added to the model, please add a part.");
      GridView1.EmptyDataTemplate = tmpEmptyDataTemplate;
      GridView1.DataBind();
  }
  
  private void MakeDataTable()
  {
      dt.Columns.Add("Item");
      dt.Columns.Add("Quantity");
      dt.Columns.Add("Price P/Quantity");
  }
  
  private void AddToDataTable()
  {
      DataRow dr = dt.NewRow();
      dr["Item"] = txtPart.Text;
      dr["Quantity"] = numQuantity.Text;
      dr["Price P/Quantity"] = txtPricePQ.Text;
      dt.Rows.Add(dr);
  }
  
  private void BindGrid()
  {
      GridView1.DataSource = dt;
      GridView1.DataBind();
  }
  
  protected void btnAddPart_Click(object sender, EventArgs e)
  {
      AddToDataTable();
      BindGrid();
      ClearNewParts();
  }
  #endregion
  </code></pre>
  
  <p>And these are some ways that I have tried to do this: (all are commented out as I moved on to the next way to do this.....</p>
  
  <pre><code>    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  {
    //  int index = Convert.ToInt32(e.CommandArgument);
      if (e.CommandName == "Edit")
      {
          if (GridView1.SelectedRow != null)
          {
              //dataTable.Rows[GridView1.SelectedRow].BeginEdit();
              //dataTable.Rows[GridView1.SelectedRow]["yourFieldName"] = newValue;
              //dataTable.Rows[GridView1.SelectedRow].EndEdit();
              //gridView.DataSource = dataTable;
          }
        //  GridViewRow row = GridView1.Rows[e.RowIndex];
  
         // Department = ((GridViewRow(((LinkButton)e.CommandSource).NamingContainer)).Cells[2].Text;
        //  txtPart.Text = GridView1.SelectedRow.Cells[1].Text;
         // txtPart.Text = GridView1.Rows[index].Cells[2].Text;
         // Response.Write(gv.Rows[index].Cells[0].Text); //consider you use bound field and the column you want to show its value is the first column.
      }
  </code></pre>
  
  <p>I know I am doing something wrong on how I am trying to achieve extracting the data out of the gridview to populate the textboxes, but not sure how.... (I'm still a junior programming and basically the first time doing what I'm trying to achieve here).... </p>