title: Write to Gridview Row when Linkbutton in Gridview clicked
body: <p>I have a <code>Gridview</code> that has a Close <code>linkbutton</code> in each row. When the users Clicks in the Close <code>Button</code>, it should write the data to that particular row. My data already writes but I when I click for example in the third row <code>linkbutton</code> Close, then it writes to the first row. I want it to write to the third row.</p>
  
  <pre><code>&lt;asp:GridView ID="gvMain" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
  Width="688px" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
  OnRowCommand="gvTransInfo_RowCommand"&gt;
  &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
  &lt;Columns&gt;
      &lt;asp:TemplateField HeaderText="Transaction Type" SortExpression="TransTypeDesc"&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:DropDownList ID="DDLTrans" runat="server" DataSourceID="SqlDataSourceTrans"
                  DataTextField="TransTypeDesc" DataValueField="TransTypeId"&gt;
              &lt;/asp:DropDownList&gt;
              &lt;asp:SqlDataSource ID="SqlDataSourceTrans" runat="server" ConnectionString="&lt;%$ ConnectionStrings:iQueueConnectionString %&gt;"
                  SelectCommand="SELECT [TransTypeId], [TransTypeDesc] FROM [tblTransType]"&gt;&lt;/asp:SqlDataSource&gt;
          &lt;/EditItemTemplate&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:Label ID="lblTrans" runat="server" Text='&lt;%# Bind("TransTypeDesc") %&gt;'&gt;&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
          &lt;ItemStyle HorizontalAlign="Center" /&gt;
      &lt;/asp:TemplateField&gt;
      &lt;asp:BoundField DataField="Received" HeaderText="Received" SortExpression="Received"&gt;
          &lt;ItemStyle HorizontalAlign="Center" /&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField DataField="Complete" HeaderText="Complete" SortExpression="Complete"&gt;
          &lt;ItemStyle HorizontalAlign="Center" /&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:BoundField DataField="TransTime" HeaderText="Est. Transaction Time" SortExpression="TransTime"&gt;
          &lt;ItemStyle HorizontalAlign="Center" /&gt;
      &lt;/asp:BoundField&gt;
      &lt;asp:TemplateField ShowHeader="False"&gt;
          &lt;ItemTemplate&gt;
              &lt;asp:LinkButton ID="lbClose" runat="server" CausesValidation="False" CommandName="CloseClicked"
                  OnClick="CloseClick_Click"&gt;Close&lt;/asp:LinkButton&gt;
              &lt;asp:LinkButton ID="lbEdit" runat="server" CausesValidation="False" CommandName="EditRow"&gt;Edit&lt;/asp:LinkButton&gt;
              &amp;nbsp;&lt;asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="DeleteRow"&gt;Cancel&lt;/asp:LinkButton&gt;
          &lt;/ItemTemplate&gt;
          &lt;EditItemTemplate&gt;
              &lt;asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="True" CommandName="UpdateRow"
                  Text="Update" CommandArgument='&lt;%# Eval("TicketId")%&gt;'&gt;&lt;/asp:LinkButton&gt;
              &amp;nbsp;&lt;asp:LinkButton ID="lbCancel" runat="server" CausesValidation="False" CommandName="CancelUpdate"
                  CommandArgument='&lt;%# Eval("TicketId")%&gt;' Text="Cancel"&gt;&lt;/asp:LinkButton&gt;
          &lt;/EditItemTemplate&gt;
          &lt;FooterStyle HorizontalAlign="Center" /&gt;
          &lt;ItemStyle HorizontalAlign="Center" /&gt;
      &lt;/asp:TemplateField&gt;
  &lt;/Columns&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>protected void CloseClick_Click(object sender, EventArgs e)
      {
          var StartLink = (Control)sender;
          GridViewRow row = (GridViewRow)StartLink.NamingContainer;
          firstCellText = row.Cells[0].Text;
      }
  </code></pre>