Wednesday, March 28, 2012

Programmatic cascading dropdown repopulation

Greetings, all...

Time for yet another plaintive cry for help out to the Ajax community.

I've got a page with four cascading dropdown lists chained together. Everything is working fine.

Where my problem comes is when I add a new row into the database (via a web service) and now I want to call the parent dropdown list and repopulate it once I receive a success code from the ws. I want to be able to do this all via client-side, and I think (hope?) I'm close, but I just can't seem to get the ddl to update its options.

Here's the code so far. As you can see, I've been trying to tackle this two ways...using a $find().populate on the dropdownlist, and, alternatively, calling the web service directly. The web service call does, in fact, retrieve all the levels, including the newly added level, but I'm not understanding how to "bind" the results to the dropdown.

function AddNewLevel()
{
var txt = document.getElementById('<%= txtAddLevel.ClientID %>')
retVal = QuestionManagerWS.AddNewLevel(txt.value, OnAddLevelOk, OnTimeout, OnError);
return(true);
}

function OnAddLevelOk(result)
{
alert(result);
// This doesn't appear to do anything...it never calls the ws, etc.
$find('<%= ddlLevel.ClientID %>').populate;

// This calls the web service and gets the correct values...but how does it bind to the ddl?
//document.getElementById('<%= ddlLevel.ClientID %>');
//QuestionManagerWS.GetLevels("","Level");
}

Anyway, I would really appreciate any help that may be out there. I've looked at the stuff in the 'manual' folder of the ToolkitTests (there's usually a gem or two in there) but nothing gives any hint on how to get this to work.

Thanks in advance,

Ric

Does anyone have any ideas on this one? I'm still stumped and need some help.

I figured out a resolution to the problem.

I've blogged about it onmy site and in a few days will be putting together an article as an example to my solution.

No comments:

Post a Comment