Gridview Verification

I am using Gridview and the Item Template text box. There are 5 text fields, and I add a new line dynamically when I click on add a btn line. in this line I add the entire text box that is empty. Now I want to check this text box on btn by clicking next.

do it now?

I used the mandatory check of the field in which it was working for the first time, showing a text field, but when I add a new text field for a line that does not cause verification, I think there is another way to give confirmation for a dynamically added text field.

How can I check my all dynamically added text box

The grid that I use.

<Columns > <asp:TemplateField> <ItemTemplate> <div class="otherOthersTd"> <asp:Label ID="lblcnt" ForeColor="#136A96" Text='<%#Eval("Count") %>' runat="server" ></asp:Label> <asp:Label ID="lblId" runat="server" text='<%#Eval("Id") %>' Visible="false"></asp:Label> </div> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="First Name"> <ItemTemplate> <asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name") %>' Width="88px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Middle Name"> <ItemTemplate> <asp:TextBox ID="txtMName" runat="server" Text='<%# Eval("MName") %>' Width="88px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Last Name"> <ItemTemplate> <asp:TextBox ID="txtLName" runat="server" Text='<%# Eval("LName") %>' Width="88px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Degree"> <ItemTemplate> <asp:TextBox ID="txtDegree" runat="Server" Text='<%# Eval("Degree") %>' Width="50px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Title"> <ItemTemplate> <asp:TextBox ID="txtTitle" runat="Server" Text='<%# Eval("Title") %>' Width="88px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Email"> <ItemTemplate> <asp:TextBox ID="txtEmail" runat="Server" Text='<%# Eval("Email") %>' Width="88px" CausesValidation="True" ValidationGroup="a"></asp:TextBox> <asp:RegularExpressionValidator ID="RegExpr" runat="server" ErrorMessage="Invalid email id" ControlToValidate="txtEmail" ValidationGroup="a" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator> <asp:Label ID="revexp" runat="server" > </asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Institution"> <ItemTemplate> <asp:TextBox ID="txtInstitution" runat="server" Text='<%#Eval("Institution") %>'></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:Button ID="btnNext" runat="server" ValidationGroup="a" CausesValidation="true" Text="Next" class="next btn" onclick="btnNext_Click"/> 

  <asp:TemplateField> <ItemTemplate> <asp:Label ID="lblAuthor" runat="server" Text="Authorerror" Visible="false" ForeColor="Red" Font-Bold="True" Font-Size="X-Large">*</asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#CCCC99" /> <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="false" ForeColor="White" /> <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" /> <HeaderStyle Font-Bold="false" ForeColor="#136A96" /> </asp:GridView> 

my code ...

 protected void GridView1_OnRowCommand1(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("")) { lstAuthors = (List<OtherAuthors>)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 < 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 < 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; } 

private bool IsValied () {bool error = false;

  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; } 

}

+4
source share
2 answers

You used the validation group ValidationGroup="a" on your next button, but you did not use it in the required field validator. But you used it in an email validator.

You must be compatible with the Validation control and whether you must test it on all controls and control buttons.

 <asp:Button ID="btnNext" runat="server" ValidationGroup="a" CausesValidation="true" Text="Next" class="next btn" onclick="btnNext_Click"/> 
+3
source

I think you should start a new page and test with a much smaller script and get this working first. Then add additional fields.

If you still need help with this smaller page, send it to help - it will be easier for us to understand it.

0
source

All Articles