Gridview and Formview Integration

G

Guest

Hello:

I have an aspx page with a Formview and a Gridview on it.

I have a dropdownlist control which I want to bind to both the Formview and
the Gridview.

I put the dropdownlist in the <InsertItemTemplate> of the Formview, so it is
binded with no problem.

I also want to use that dropdownlist's SelectedValue as a parameter that
determines the data displayed in my Gridview.

But now, how do I programatically access that dropdownlist SelectedValue
within the Gridview if it is in the Formview's <InsertItemTemplate>?
 
C

Chris Durkin

Controls inside a FormView can be accessed using the
FormView.FindControl method:

DropDownList ddl = (DropDownList) fv.FindControl("nameofddl");

Obviously you would want to refine the above by first checking if the
control were returned and if it were of the correct type. Best practice
would be to have the page implement an Interface with a Property to
return the DropDown.

The FormView creates its controls dynamically depending on the Mode and
which template is loaded. FindControl will not return the desired
control until after the FormView's Controls collection has been
populated. The FormView's PreRender method is one place where it is
safe to use FindControl. You might also use Page.LoadComplete.


HTH,
Chris
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top