title: Asp.net GridView OnRowUpdating
body: <p>I am using <code>OnRowUpdating</code> in my gridview. It's fairly straight forward but for some reason it's not updating. It's as if it's not finding the <code>EditTemplate</code> controls. It's a bit different of a set up, as all the controls are in a single column (maybe this is causing the problems?) and it's set up in a "blog" format. I do not receive any runtime errors, so it must be logic. Here is the asp.</p>
  
  <p><strong>ASP</strong></p>
  
  <pre><code>&lt;asp:GridView ID="gvPosts" runat="server" AutoGenerateColumns="False" DataKeyNames="MessageID" GridLines="Vertical" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" Width="693px"
               OnPageIndexChanging="gvPosts_PageIndexChanging" OnRowEditing="gvPosts_RowEditing"
               OnRowCancelingEdit="gvPosts_RowCancelingEdit" OnRowUpdating="gvPosts_RowUpdating" AllowPaging="True"&gt;
              &lt;AlternatingRowStyle BackColor="#CCCCCC" /&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField HeaderText="Posts" HeaderStyle-Font-Size="Larger"&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:Textbox ID="tbGridTitle" runat="server" Text='&lt;%# Bind("Title") %&gt;' Font-Bold="true" Font-Size="Large" ForeColor="#cc0000"&gt;&lt;/asp:Textbox&gt;
                          &lt;div style="margin-left: 20px"&gt;
                              &lt;p&gt;
                                  &lt;asp:Textbox ID="tbGridAuthor" runat="server" Text='&lt;%# Bind("Author") %&gt;' Font-Bold="true" Font-Size="Small" Width="150px"&gt;&lt;/asp:Textbox&gt;                             
                                  &lt;asp:label ID="lblDate" runat="server" Text='&lt;%# Bind("Date","{0:MM/dd/yyyy}") %&gt;' Font-Bold="true" Font-Size="Small" Width="100px"&gt;&lt;/asp:label&gt;
                                  &lt;asp:label ID="lblIPAddress" runat="server" Text='&lt;%# Bind("IPAddress") %&gt;' Font-Bold="true" Font-Size="Small" Width="100px" Visible="false"&gt;&lt;/asp:label&gt;
                                  &lt;%--&lt;asp:Label ID="lblMID" runat="server" Text='&lt;%# "ImageHandler.ashx?mid="+ Eval("MessageID") %&gt;'&gt;&lt;/asp:Label&gt;--%&gt;
                              &lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div style="margin-left: 40px"&gt;
                              &lt;asp:TextBox ID="tbGridMessage" runat="server" Text='&lt;%# Bind("Message") %&gt;' TextMode="MultiLine" Width="450px"&gt;&lt;/asp:TextBox&gt;
                              &lt;div&gt;
                                  &lt;asp:Image ID="postImage" runat="server" ImageUrl='&lt;%# "ImageHandler.ashx?mid="+ Eval("MessageID") %&gt;' Width="400px" AlternateText="No Image" ImageAlign="Middle" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="Label4" runat="server" Text='&lt;%# Bind("Title") %&gt;' Font-Bold="true" Font-Size="Large" ForeColor="#cc0000"&gt;&lt;/asp:Label&gt;
                          &lt;div style="margin-left: 20px"&gt;
                              &lt;p&gt;
                                  &lt;asp:Label ID="Label1" runat="server" Text='&lt;%# Bind("Author") %&gt;' Font-Bold="true" Font-Size="Small" Width="150px"&gt;&lt;/asp:Label&gt;                             
                                  &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Bind("Date","{0:MM/dd/yyyy}") %&gt;' Font-Bold="true" Font-Size="Small" Width="100px"&gt;&lt;/asp:Label&gt;
                                  &lt;asp:Label ID="lblIPAddress" runat="server" Text='&lt;%# Bind("IPAddress") %&gt;' Font-Bold="true" Font-Size="Small" Width="100px" Visible="false"&gt;&lt;/asp:Label&gt;
                                  &lt;%--&lt;asp:Label ID="lblMID" runat="server" Text='&lt;%# "ImageHandler.ashx?mid="+ Eval("MessageID") %&gt;'&gt;&lt;/asp:Label&gt;--%&gt;
                              &lt;/p&gt;
                          &lt;/div&gt;
                          &lt;div style="margin-left: 40px"&gt;
                              &lt;asp:Label ID="Label3" runat="server" Text='&lt;%# Bind("Message") %&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;div&gt;
                                  &lt;asp:Image ID="postImage" runat="server" ImageUrl='&lt;%# "ImageHandler.ashx?mid="+ Eval("MessageID") %&gt;' Width="400px" AlternateText="No Image" ImageAlign="Middle" Visible="false" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;HeaderStyle Font-Size="Large" /&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:LinkButton runat="server" Text="View Comments" OnClick="lbViewComments_Click"&gt;&lt;/asp:LinkButton&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField HeaderText="MessageID" SortExpression="MessageID" Visible="true"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:Label ID="lblMessageID" runat="server" Text='&lt;%# Bind("MessageID") %&gt;'&gt;&lt;/asp:Label&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField ShowHeader="False"&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:LinkButton ID="lbUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update"&gt;&lt;/asp:LinkButton&gt;
                          &amp;nbsp;&lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel"&gt;&lt;/asp:LinkButton&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
                  &lt;asp:TemplateField ShowHeader="False" Visible="False"&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:LinkButton ID="lbDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClick="lbDelete_Click"&gt;&lt;/asp:LinkButton&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>And here is my code behind for the RowUpdating..</p>
  
  <p><strong>C#</strong></p>
  
  <pre><code>    protected void gvPosts_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {
          GridViewRow gvr = (GridViewRow)gvPosts.Rows[e.RowIndex];
  
          int MessageID = Convert.ToInt32(gvPosts.DataKeys[e.RowIndex].Value.ToString());
          TextBox Title = (TextBox)gvr.FindControl("tbGridTitle");
          TextBox Message = (TextBox)gvr.FindControl("tbGridMessage");
          TextBox Author = (TextBox)gvr.FindControl("tbGridAuthor");
  
          try
          {
              conn.Open();
              SqlCommand cmdUpdate = new SqlCommand("UPDATE BlogMessages SET Title = @Title, Message = @Message, Author = @Author WHERE MessageID = @MessageID", conn);
              cmdUpdate.Parameters.AddWithValue("@MessageID", MessageID);
              cmdUpdate.Parameters.AddWithValue("@Title", Title.Text);
              cmdUpdate.Parameters.AddWithValue("@Message", Message.Text);
              cmdUpdate.Parameters.AddWithValue("@Author", Author.Text);
              cmdUpdate.ExecuteNonQuery();
              conn.Close();
  
              gvPosts.EditIndex = -1;
  
              DataBound();
              GridControls();
          }
          catch (Exception ex)
          {
              lblMessage.Text = "Couldn't update! " + ex.ToString();
          }
      }
  </code></pre>
  
  <p>Everything else like the <code>RowEditing</code> and <code>RowEditCanceling</code> but for some reason, I'm unable to update. I think some fresh eyes might be able to catch what I'm missing. </p>
  
  <p>I have also tried this for finding the controls but no luck. </p>
  
  <pre><code>TextBox Title = (TextBox)gvPosts.Rows[e.RowIndex].FindControl("tbGridTitle");
  </code></pre>
  
  <p>I have tried multiple things but I don't remember them all. Thanks in advance!</p>