aspx
code behind file in aspx.cs in submit button event.
for (int i = 0; i < gvAcademicQualification.Rows.Count; i++)
{
// Only perform validation for the first, second, and third rows not on 4th row
if (i == 3)
{
GridViewRow row = gvAcademicQualification.Rows[i];
// Find the TextBox controls within the row
TextBox txtStream = (TextBox)row.FindControl("txtStream");
TextBox txtInstituteName = (TextBox)row.FindControl("txtInstituteName");
TextBox txtGrade = (TextBox)row.FindControl("txtGrade");
TextBox txtYearOfPassing = (TextBox)row.FindControl("txtYearOfPassing");
// Perform validation for the desired fields
if (string.IsNullOrEmpty(txtStream.Text))
{
// Handle the validation error for Stream field
// You can display an error message or highlight the invalid row
RequiredFieldValidator rtxtStream = FindControl("rtxtStream") as RequiredFieldValidator;
if (rtxtStream != null)
rtxtStream.Visible = false;
}
if (string.IsNullOrEmpty(txtInstituteName.Text))
{
// Handle the validation error for Institute Name field
// You can display an error message or highlight the invalid row
RequiredFieldValidator rtxtStream = FindControl("rtxtStream") as RequiredFieldValidator;
if (rtxtStream != null)
rtxtStream.Visible = false;
}
if (string.IsNullOrEmpty(txtGrade.Text))
{
// Handle the validation error for Grade field
// You can display an error message or highlight the invalid row
RequiredFieldValidator rtxtStream = FindControl("rtxtStream") as RequiredFieldValidator;
if (rtxtStream != null)
rtxtStream.Visible = false;
}
if (string.IsNullOrEmpty(txtYearOfPassing.Text))
{
// Handle the validation error for Year of Passing field
// You can display an error message or highlight the invalid row
RequiredFieldValidator rtxtStream = FindControl("rtxtStream") as RequiredFieldValidator;
if (rtxtStream != null)
rtxtStream.Visible = false;
}
}
}
Jignesh KumarPosted Jan 12, 2024, 4:52 AM
Hello Sumit,
Please check the last index of your gridview and check the condition for that and you can skip validation for that,
Amit MohantyPosted Jan 11, 2024, 11:50 AM
Your question is a bit confusing for me. Can you provide additional information, including the problem you're encountering and what result you're expecting?
If you want to skip validation on last row of the gridview then:
If you want to perform validation for the first, second, and third rows:
Sachin SinghPosted Jan 11, 2024, 6:54 AM
Please test this