Wednesday, March 21, 2012

CascadingDropDown inside of a repeater

I'm trying to create a CascadingDropDown inside of a repeater, and just can't seem to figure it out.

I have a dropdownlist created within a repeater that should cascade from another dropdownlist that is also generated within the repeater.

The problem that arises from this situation is when I go to set the CascadingDropDownProperties, I get this error:

Object reference not set to an instance of an object.

Description:Anunhandled exception occurred during the execution of the current webrequest. Please review the stack trace for more information about theerror and where it originated in the code.

Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of thecurrent web request. Information regarding the origin and location ofthe exception can be identified using the exception stack trace below.


Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
AtlasControlToolkit.CascadingDropDown.OnPreRender(EventArgs e) in d:\Depot\Atlas\agility\AtlasControls\MAIN\Src\ControlLibrary\CascadingDropDown\CascadingDropDownExtender.cs:60
System.Web.UI.Control.PreRenderRecursiveInternal() +77
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Control.PreRenderRecursiveInternal() +161
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360


When I go through with the debugger it doesn't break on any line of code, so I'm not totally sure what's causing the error. I have figured out that the problem happens when I set the TargetControlID, because If I comment out that line then It'll work. I'm guessing I'll have the same problems with the ParentControlID, also.

cddpNew.TargetControlID = DropDownListControl.ClientID

Has anyone gotten a Cascading drop down to work within a repeater?Since that didn't work I decided to take another approach, which is to put the CascadingDropDown inside the repeater. This had it's own problem.

When trying to get the control from within the repeater during the function that handles the databinding event for the repeater I get the error:

Value of type 'System.Web.UI.Control cannot be converted to 'AtlasControlToolkit.CascadingDropDownProperties'.

So, no luck this direction either.Sad
In the first case, you probably need to access the CascadingDropDown through the Repeater container (recall that the Repeater creates many instances of its contents). The way ASP.NET implements repeaters is a little tricky, but I think you should be able to accomplish what you want with the right code.

No comments:

Post a Comment