Beejee
Beejee

Reputation: 2016

ValidatorCalloutExtender not displaying in Gridview

The title speaks for itself but here is the situation. I have a page with 2 gridviews. The first one is used to search products you want use. These articles can be added to the other gridview. This second gridview contains all the selected items with a textbow where the user can change the amount they want to use.

Now comes the problem, I added a valdiator to the textbox which makes sure that the amount isn't higher than the amount which is available in the stock.

I added the ValidatorCalloutExtender to this validator. Whenever the validation is caused the message isn't displayed. The validator works because I can't go further untill I change the amount to the right value.

The css class I used to customize the ValidatorCalloutExtender works on all my other pages. where it isn't used in a gridview.

Is there any way to make this work when not used in the editTemplate of the gridview?

Upvotes: 0

Views: 747

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460238

I'm assuming that it is not working because of the ValidationGroup. It should be unique for all GridView-Rows. This could be achieved for example by using the GridView's RowDataBound event to set it programmatically:

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
      if (e.Row.RowType == DataControlRowType.DataRow)
      {
            TextBox tbx = (TextBox)e.Row.FindControl("MyTextBox");
            RequiredFieldValidator rfv = (RequiredFieldValidator)e.Row.FindControl("MyReq");
            string validationGroupText = "ValidationTest" + (e.Row.DataItemIndex + 1).ToString();
            tbx.ValidationGroup = validationGroupText;
            rfv.ValidationGroup = validationGroupText;
      }
}

Upvotes: 2

Related Questions