EditTemplate controls inaccessible in CustomValidator servervalidate event handler

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.
 
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.

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top