EditTemplate controls inaccessible in CustomValidator servervalidate event handler

  • Thread starter Thread starter Aamir Ghanchi
  • Start date Start date
A

Aamir Ghanchi

Like thr subject line says. I get no intellisense in VS 2005 as well
as get the compilation message "The name 'ddlCourse1' does not exist
in the current context".
Is there a way to have access to the controls being validated in the
EditTemplate of gridview.
The CustomValidator control itself is outside the gridview, but I have
tried putting it in a template column of gridview alongside with Edit/
Update linked buttons but to no avail.

I have akready scoured the newsgroup for the solutions, but found ni
similar topics.

Any leads will be aappreciated.

Thanks.
 
Like thr subject line says. I get no intellisense in VS 2005 as well
as get the compilation message "The name 'ddlCourse1' does not exist
in the current context".
Is there a way to have access to the controls being validated in the
EditTemplate of gridview.
The CustomValidator control itself is outside the gridview, but I have
tried putting it in a template column of gridview alongside with Edit/
Update linked buttons but to no avail.

I have akready scoured the newsgroup for the solutions, but found ni
similar topics.

Any leads will be aappreciated.

Thanks.

Answering my own post with solution:
The issue had more to do with referencing the controls that are in the
EditemItemTemplate than it has to do with the CusotmValidator itself.
such controls are not directly available and have to be referred
through the GridViewRow being and calling its FindControl method with
the ID of the control you need.

//In the CustomValidator's ServerValidate event handler
//Get reference to the row being edited
GridViewRow editedRow = GridView1.Rows[GridView1.EditIndex];

//Get reference to the course dropdownlists
DropDownList ddlCourse1 =
(DropDownList)editedRow.FindControl("ddlCourse1");

//now use ddlCourse1 variable as you normally would use a control.

Cheers!
 
Back
Top