Disabling GridView Validation
If you want to put a gridview on a form with validators, you’ll run into validation issues very quickly. The LinkButton controls cause the page validation. Immediately I looked for a "ValidationGroup" property on the GridView, but unfortunately, none exists.
![]()
The solution is to handle the "DataBound" event on the GridView, and manually find the link buttons. The following code loops through the controls in the first cell of the row currently being edited.
protected void Page_Load(object sender, EventArgs e)
{
dgMyGrid.DataBound += dgMyGrid_DataBound;
}
private void dgMyGrid_DataBound(object sender, EventArgs e)
{
if (dgMyGrid.EditIndex >= 0)
{
//Turn off validation on the link buttons, because we don't want other page validation issues interfering.
foreach (Control currControl in dgMyGrid.Rows[dgMyGrid.EditIndex].Cells[0].Controls)
{
LinkButton lb = currControl as LinkButton;
if (lb != null)
lb.ValidationGroup = "no-validation";
}
}
}

sandeep said,
Wrote on January 7, 2009 @ 9:17 am
set cause validation property of the button to
false
Thomas said,
Wrote on July 10, 2009 @ 3:15 pm
This helped me out a lot, but it led me to what I believe is a better solution — put the form elements you don’t want validated when gridview links are clicked in their own validation group.
Wagner said,
Wrote on March 14, 2010 @ 7:04 am
Very good advice, thank you! Prevented me from some long code writing.
Sandeep is wrong, you can not edit ’causes validation’ tag of buttons in commandfields.
Eric Barr said,
Wrote on July 2, 2010 @ 3:38 pm
Yes, I like Thomas’s solution. I didn’t have to handle any events, just set the validation group on the form that is outside the grid and the button that submits that form. That worked very well. Thanks for the post!