Saturday, March 24, 2012

Validation Controls not working in GridView

Hi All,

How do we set validation controls such as Required Field,Regular Express in GridView Footer Template TextBox flds?

I would like to check validation on GridView Footer Template Button Click for inserting

This is the code behind

protectedvoid GridView1_RowCommand(object sender,GridViewCommandEventArgs e)

{

if (e.CommandName =="AddUser")

{

}

But the validation controls are not working.Any help would be highly appreciated?

Hi,

Use the FooterRow.FindControl and find both the validation controls and the text fields. Now, assign the ClientID of the text fields to the validation controls

CType(FooterRow.FindControl("rfv1"),RequiredFieldValidator).ControlToValidate = CType(FooterRow.FindControl("txt1"),TextBox).ClientID

HTH
Regards


Hi,

Thanks for your reply.I got it

I changed it to

((RequiredFieldValidator)GridView1.FooterRow.FindControl("Req_ID")).ControlToValidate = ((TextBox)GridView1.FooterRow.FindControl("txtUserID")).ClientID;

No comments:

Post a Comment