title: Gridview Validation
body: <p>I am using Gridview and using Item Template text box. There are 5 text box and i am adding a new row dynamically on clicking on add row btn. in that row i have adding all text box which is empty. Now i want to validate that text box on btn click next.</p>
  
  <p>now to do it?</p>
  
  <p>I used required field validation its working for first time showing text box but when i am adding a new row text box its not causing the validation, I think there is some other way to give validation for dynamically added text box.</p>
  
  <p>How could i validation my all dynamically added text box</p>
  
  <p>Grid view which i am using..</p>
  
  <p></p>
  
  <pre><code>            &lt;Columns &gt;
  
                      &lt;asp:TemplateField&gt;
                      &lt;ItemTemplate&gt;
                          &lt;div class="otherOthersTd"&gt;
                              &lt;asp:Label ID="lblcnt" ForeColor="#136A96" Text='&lt;%#Eval("Count") %&gt;' runat="server" &gt;&lt;/asp:Label&gt;
                              &lt;asp:Label ID="lblId" runat="server" text='&lt;%#Eval("Id") %&gt;' Visible="false"&gt;&lt;/asp:Label&gt;
                          &lt;/div&gt;
                      &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
                     &lt;asp:TemplateField HeaderText="First Name"&gt;
  
                              &lt;ItemTemplate&gt;
  
                                  &lt;asp:TextBox ID="txtName" runat="server" Text='&lt;%# Eval("Name") %&gt;' Width="88px"&gt;&lt;/asp:TextBox&gt;
  
                              &lt;/ItemTemplate&gt;
  
  
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Middle Name"&gt;
  
                              &lt;ItemTemplate&gt;
  
                                  &lt;asp:TextBox ID="txtMName" runat="server" Text='&lt;%# Eval("MName") %&gt;' 
                                       Width="88px"&gt;&lt;/asp:TextBox&gt;
  
                              &lt;/ItemTemplate&gt;
  
                      &lt;/asp:TemplateField&gt;
                      &lt;asp:TemplateField HeaderText="Last Name"&gt;
  
                              &lt;ItemTemplate&gt;
  
                                  &lt;asp:TextBox ID="txtLName" runat="server" Text='&lt;%# Eval("LName") %&gt;' 
                                       Width="88px"&gt;&lt;/asp:TextBox&gt;
                              &lt;/ItemTemplate&gt;
  
                      &lt;/asp:TemplateField&gt;
  
                      &lt;asp:TemplateField HeaderText="Degree"&gt;
  
                              &lt;ItemTemplate&gt;
  
                                  &lt;asp:TextBox ID="txtDegree" runat="Server" Text='&lt;%# Eval("Degree") %&gt;' 
                                      Width="50px"&gt;&lt;/asp:TextBox&gt; 
  
                              &lt;/ItemTemplate&gt;
  
  
                      &lt;/asp:TemplateField&gt;
  
                      &lt;asp:TemplateField HeaderText="Title"&gt;
  
                              &lt;ItemTemplate&gt;
                                  &lt;asp:TextBox ID="txtTitle" runat="Server" Text='&lt;%# Eval("Title") %&gt;' Width="88px"&gt;&lt;/asp:TextBox&gt;
  
                              &lt;/ItemTemplate&gt;
  
  
                      &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Email"&gt;
                       &lt;ItemTemplate&gt; 
                              &lt;asp:TextBox ID="txtEmail" runat="Server" 
                                  Text='&lt;%# Eval("Email") %&gt;' Width="88px" CausesValidation="True" ValidationGroup="a"&gt;&lt;/asp:TextBox&gt;
                          &lt;asp:RegularExpressionValidator ID="RegExpr" runat="server" ErrorMessage="Invalid email id" ControlToValidate="txtEmail" ValidationGroup="a" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"&gt;&lt;/asp:RegularExpressionValidator&gt;
                           &lt;asp:Label ID="revexp" runat="server"  &gt; &lt;/asp:Label&gt;
                              &lt;/ItemTemplate&gt;
  
                  &lt;/asp:TemplateField&gt;
  
                  &lt;asp:TemplateField HeaderText="Institution"&gt;
  
                          &lt;ItemTemplate&gt;
                              &lt;asp:TextBox ID="txtInstitution" runat="server" Text='&lt;%#Eval("Institution") %&gt;'&gt;&lt;/asp:TextBox&gt;
  
                          &lt;/ItemTemplate&gt;
  
                  &lt;/asp:TemplateField&gt;
  
  
       &lt;asp:Button ID="btnNext" runat="server" ValidationGroup="a" CausesValidation="true" Text="Next" class="next btn" onclick="btnNext_Click"/&gt;        
  </code></pre>
  
  <p>
                          </p>
  
  <pre><code>                    &lt;asp:TemplateField&gt;  &lt;ItemTemplate&gt;
                       &lt;asp:Label ID="lblAuthor" runat="server" Text="Authorerror" Visible="false"  ForeColor="Red" Font-Bold="True" Font-Size="X-Large"&gt;*&lt;/asp:Label&gt;
          &lt;/ItemTemplate&gt;
                      &lt;/asp:TemplateField&gt;
  
  
              &lt;/Columns&gt;
  
              &lt;FooterStyle BackColor="#CCCC99" /&gt;
              &lt;SelectedRowStyle BackColor="#CE5D5A" Font-Bold="false" ForeColor="White" /&gt;
              &lt;PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /&gt;
              &lt;HeaderStyle  Font-Bold="false" ForeColor="#136A96" /&gt;
  
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>my code...</p>
  
  <pre><code>protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e)
          {
  
          if (e.CommandName.Equals(""))
          {
              lstAuthors = (List&lt;OtherAuthors&gt;)Session["lstAuthors"];
              if (lstAuthors.Count == 0)
              {
                  OtherAuthors obj0 = new OtherAuthors();
                  obj0.Count = "Author 1:";                    
                  lstAuthors.Add(obj0);
              }
              int index=GridView1.Rows.Count-1;
              for (int i = 0; i &lt; GridView1.Rows.Count; i++)
              {
                  TextBox Name = GridView1.Rows[i].FindControl("txtName") as TextBox;
                  TextBox MName = GridView1.Rows[i].FindControl("txtMName") as TextBox;
                  TextBox LName = GridView1.Rows[i].FindControl("txtLName") as TextBox;
                  TextBox Degree = GridView1.Rows[i].FindControl("txtDegree") as TextBox;
                  TextBox Title = GridView1.Rows[i].FindControl("txtTitle") as TextBox;
                  TextBox Email = GridView1.Rows[i].FindControl("txtEmail") as TextBox;
                  TextBox Institution = GridView1.Rows[i].FindControl("txtInstitution") as TextBox;
  
                  if(Name!=null)
                  {
  
                  lstAuthors[i].Name = Name.Text;
                  lstAuthors[i].MName = MName.Text;
                  lstAuthors[i].LName = LName.Text;
                  lstAuthors[i].Degree = Degree.Text;
                  lstAuthors[i].Title = Title.Text;
                  lstAuthors[i].Email = Email.Text;
                  lstAuthors[i].Institution = Institution.Text;
                  }
              }
              OtherAuthors obj1 = new OtherAuthors();
              obj1.Count = "Author "+(lstAuthors.Count+1).ToString()+":";
             obj1.Name="";
             lstAuthors.Add(obj1);
  
             GridView1.DataSource = lstAuthors;
             GridView1.DataBind();
             for (int i = 0; i &lt; GridView1.Rows.Count; i++)
             {
                 if (GridView1.Rows.Count - 1 == i)
                     GridView1.Rows[i].Cells[8].Visible = true;
                 else
                     GridView1.Rows[i].Cells[8].Visible = false;
             }
             Session["lstAuthors"] = lstAuthors;
          }
          MultipleModalitySelect1.hideChosebutton = true;
  
      }
  </code></pre>
  
  <p>private bool IsValied()
          {
              bool error = false;</p>
  
  <pre><code>            TextBox Name = GridView1.Rows[0].FindControl("txtName") as TextBox;
              TextBox MName = GridView1.Rows[0].FindControl("txtMName") as TextBox;
              TextBox LName = GridView1.Rows[0].FindControl("txtLName") as TextBox;
              TextBox Degree = GridView1.Rows[0].FindControl("txtDegree") as TextBox;
              TextBox Title = GridView1.Rows[0].FindControl("txtTitle") as TextBox;
              TextBox Email = GridView1.Rows[0].FindControl("txtEmail") as TextBox;
              TextBox Institution = GridView1.Rows[0].FindControl("txtInstitution") as TextBox;
              Label lblAuthor = GridView1.Rows[0].FindControl("lblAuthor") as Label;
  
              if (Name.Text.Length == 0 || LName.Text.Length == 0 || Degree.Text.Length == 0 ||Title.Text.Length == 0 || Email.Text.Length == 0 || Institution.Text.Length == 0)
              {
                  lblAuthor.Visible = true;
                  error = true;
  
              }
              else
              {
                  lblAuthor.Visible = false;
              }
  </code></pre>
  
  <p>}</p>