title: Gridview check all rows before update
body: <p>I have a gridview that has a sqldatasource. My Data should be like this:  </p>
  
  <p><img src="https://i.stack.imgur.com/Y6JKI.png" alt="Desired"></p>
  
  <p>But on any row, when I click EDIT button, and then "Update" button, I want to check that its previous row "Ending_Price" must be less than this row's Start_Price. Also This row's End_Price must be less than next Row's Start Price.</p>
  
  <p>If this doesn' happen, then user must be notified as This range must be in order.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>        protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
      {
  
  
          if (e.RowIndex == 0 &amp;&amp; GridView1.Rows.Count != 1)
          {
              // Next Row Starting Value
              TextBox txtNextStartingPoint = GridView1.Rows[e.RowIndex + 1].FindControl("txtStartingRange") as TextBox;
  
              // This row ending value
              TextBox txtThisEndingRange = GridView1.Rows[e.RowIndex].FindControl("txtEndingRange") as TextBox;
  
              if (Convert.ToDecimal(txtThisEndingRange.Text) &gt;= Convert.ToDecimal(txtNextStartingPoint))
              {
                  NotificationHelper.ShowError(this, "Invalid Ending Value");
                  e.Cancel = true;
                  return;
              }
  
          }
  
          TextBox txtStartingPoint = GridView1.Rows[e.RowIndex].FindControl("txtStartingRange") as TextBox;
          TextBox txtEndingRange = GridView1.Rows[e.RowIndex].FindControl("txtEndingRange") as TextBox;
          TextBox txtDiscount_Percentage = GridView1.Rows[e.RowIndex].FindControl("txtDiscount_Percentage") as TextBox;
          Label txtDiscount_ID = GridView1.Rows[e.RowIndex].FindControl("lblId") as Label;
  
  
          SqlDataSource1.UpdateParameters["sr"].DefaultValue = txtStartingPoint.Text;
          SqlDataSource1.UpdateParameters["re"].DefaultValue = txtEndingRange.Text;
          SqlDataSource1.UpdateParameters["perc"].DefaultValue = txtDiscount_Percentage.Text;
          SqlDataSource1.UpdateParameters["discount_ID"].DefaultValue = txtDiscount_ID.Text;
  
  
          SqlDataSource1.Update();
      }
  
  
  
      /// &lt;summary&gt;
      /// Edit record
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;&lt;/param&gt;
      /// &lt;param name="e"&gt;&lt;/param&gt;
      protected void editRecord(object sender, GridViewEditEventArgs e)
      {
          // Get the current row index for edit record
          GridView1.EditIndex = e.NewEditIndex;
  
      }
  
  
      protected void cancelRecord(object sender, GridViewCancelEditEventArgs e)
      {
          GridView1.EditIndex = -1;
      }
  </code></pre>
  
  <p>This returns a null value:</p>
  
  <pre><code>  TextBox txtNextStartingPoint = GridView1.Rows[e.RowIndex + 1].FindControl("txtStartingRange") as TextBox;
  </code></pre>
  
  <p>Here is my gridview Markup</p>
  
  <pre><code>   &lt;asp:GridView ID="GridView1" runat="server" ShowHeaderWhenEmpty="True" AutoGenerateColumns="False"
                  OnRowCancelingEdit="cancelRecord" OnRowEditing="editRecord" OnRowUpdating="UpdateRecord"
                  CellPadding="4" GridLines="None" Width="673px" ForeColor="#333333" 
                  DataSourceID="SqlDataSource1" OnDataBound="GridView1_DataBound"
                  &gt;
                  &lt;RowStyle HorizontalAlign="Center" /&gt;
                  &lt;AlternatingRowStyle BackColor="White" /&gt;
                  &lt;EditRowStyle BackColor="#7C6F57" /&gt;
                  &lt;FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" /&gt;
                  &lt;HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /&gt;
                  &lt;PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /&gt;
                  &lt;RowStyle BackColor="#E3EAEB" /&gt;
                  &lt;SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /&gt;
                  &lt;Columns&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;HeaderTemplate&gt;
                              Id&lt;/HeaderTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblId" runat="server" Text='&lt;%#Bind("discount_id")%&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;HeaderTemplate&gt;
                              Starting Point&lt;/HeaderTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblStartingRange" runat="server" Text='&lt;%#Bind("starting_range") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox ID="txtStartingRange" runat="server" Text='&lt;%#Bind("starting_range") %&gt;'
                                  MaxLength="50"&gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;FooterTemplate&gt;
                              &lt;asp:TextBox ID="txtNewStartingRange" runat="server" MaxLength="50"&gt;&lt;/asp:TextBox&gt;
                          &lt;/FooterTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;HeaderTemplate&gt;
                              Ending Range&lt;/HeaderTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lblEndingRange" runat="server" Text='&lt;%#Bind("ending_range") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox ID="txtEndingRange" runat="server" Text='&lt;%#Bind("ending_range") %&gt;'
                                  MaxLength="2"&gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;FooterTemplate&gt;
                              &lt;asp:TextBox ID="txtEndingRange" runat="server" MaxLength="2"&gt;&lt;/asp:TextBox&gt;
                          &lt;/FooterTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;HeaderTemplate&gt;
                              Discount Percentage&lt;/HeaderTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Label ID="lbldiscount_percentage" runat="server" Text='&lt;%#Bind("discount_percentage") %&gt;'&gt;&lt;/asp:Label&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:TextBox ID="txtDiscount_Percentage" runat="server" Text='&lt;%#Bind("discount_percentage") %&gt;'
                                  MaxLength="10"&gt;&lt;/asp:TextBox&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;FooterTemplate&gt;
                              &lt;asp:TextBox ID="txtNewDiscount_Percentage" runat="server" MaxLength="10"&gt;&lt;/asp:TextBox&gt;
                          &lt;/FooterTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField&gt;
                          &lt;HeaderTemplate&gt;
                              Operation&lt;/HeaderTemplate&gt;
                          &lt;ItemTemplate&gt;
                              &lt;asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" /&gt;
                              &lt;asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" CausesValidation="true"
                                  OnClientClick="return confirm('Are you sure?')" /&gt;
                          &lt;/ItemTemplate&gt;
                          &lt;EditItemTemplate&gt;
                              &lt;asp:Button ID="btnUpdate" runat="server" CommandName="Update" Text="Update" /&gt;
                              &lt;asp:Button ID="btnCancel" runat="server" CommandName="Cancel" Text="Cancel" CausesValidation="false" /&gt;
                          &lt;/EditItemTemplate&gt;
                          &lt;FooterTemplate&gt;
                          &lt;/FooterTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                  &lt;/Columns&gt;
                  &lt;EmptyDataTemplate&gt;
                      No record available
                  &lt;/EmptyDataTemplate&gt;
              &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>What should I do about it? Any idea?</p>