Last post Jun 17, 2010 01:01 PM by sjnaughton
Jun 16, 2010 02:16 PM|austinco|LINK
Hello all, I am using steves Cascading Field Template for a project I am working on, when I use it in a GridView Control as in his tutorial it works awesomely, but when I put the fields in a FormView it gives me a null reference error. As far as I could
see through debugging is that I needed to change the fields Parent control property from GridView to FormView, but no luck there. I suspect that it is because it is looking inside the formview control but is NOT looking in the EditItemTemplate where the control
protected void Page_Load(object sender, EventArgs e)
if (DropDownList1.Items.Count == 0)
DropDownList1.Items.Add(new ListItem("[Not Set]", ""));
// get dependee field
var dependeeField = this.GetDependeeField<FormView /* THIS IS WHAT I CHANGED FROM GRIDVIEW TO FORMVIEW */>(Column);
// add event handler if dependee exists
if (dependeeField != null)
dependeeField.SelectionChanged += SelectedIndexChanged;
Jun 16, 2010 06:28 PM|sjnaughton|LINK
Hi Austin, can I assume you are running this in DD4 and VS2010?
Jun 16, 2010 11:30 PM|austinco|LINK
this is in 3.5 in VS2010.
Jun 17, 2010 04:54 AM|sjnaughton|LINK
Hi Austin, so you are creating a Custom page that uses a FormView?
Jun 17, 2010 09:01 AM|austinco|LINK
Yes I am.
EDIT: I should probably mention that it is nested in a table within the FormViews EditItemTemplate.
Jun 17, 2010 09:18 AM|sjnaughton|LINK
OK so what I've been using is this in my early FormView pages
/// Get the control by searching recursively for it.
/// <param name="Root">The control to start the search at.</param>
/// <param name="Id">The ID of the control to find</param>
/// <returns>The control the was found or NULL if not found</returns>
public static Control FindControlRecursive(this Control Root, string Id)
if (Root.ID == Id)
foreach (Control Ctl in Root.Controls)
Control FoundCtl = FindControlRecursive(Ctl, Id);
if (FoundCtl != null)
// get value of dev ddl (Community)
var formView = this.GetParent<DataBoundControl>();
// get parent control // note: you must specify the container control type in;// DetailsView and FormView = CompositeDataBoundControl : DataBoundControl// ListView = DataBoundControlvar dependantDynamicControl = formView.FindControlRecursive(DEPENDANT_COLUMN) as DynamicControl;
This works because both FormView, ListView and DetailsView both inherit from DataBoundControl and so the field template will work with and data control in DD.
Jun 17, 2010 10:17 AM|austinco|LINK
That worked! Can't belive I spent an entire afternoon scratching my head over that one word. >.<
BTW, you are my DD hero for making that dropdown template.
Jun 17, 2010 01:01 PM|sjnaughton|LINK
Hi Austin have you seen the new one here:
This one does not require multiple field templates and all but the Filter will work in DD1 also [:)]