Gridview and Formview Integration

  • Thread starter Thread starter Guest
  • Start date Start date
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>?
 
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
 
Back
Top