Monthly Archives: February 2011

ASP DropDownList DataBind Woes – Invalid SelectedValue Error

Yesterday, as I was plugging away on an ASP WebForms application to add some new features, I encountered an error I had not yet seen.

“SelectedValue which is invalid because it does not exist in the list of items”

Although Googling turned up a lot of results, I could not really find anything that fit the bill as a solution.  I did find a few threads on StackOverflow, though usually these discussions were followed up with additional people asking how the original asker resolved the issue.

For me, it turns out that I was calling the block of code that performed the list population and databind multiple times.  Populating and calling DataBind on this DropDownList multiple times, resulted in the above error.  In the end (after much forehead beating), the solution was an easy one – checking items before attempting to populate and bind to ensure the list was not already initialized.

if (yourDropDownList.Items.Count() == 0) //only populate and bind if not already done…
{
//populate and bind
}

That is it – just checking to ensure the items for the drop down list have not already been populated.  Of course, you really should have your application structured so that this logic is only hit once…. This said, if a complete refactor/rewrite is not in the cards for your application at this time, you can just perform this simple check to work around the exception.

Hope this helps someone!

-Matt

Critical error on Couchapp push with Ubuntu

I am hoping that in posting this, someone is able to save a little time and frustration.

On my Ubuntu 10.10 machine with CouchDB 1.0.1 installed, I began experiencing the following error every time I attempted to ‘couchapp push’ my couchapp changes:

[CRITICAL] Expecting object: line 2 column 3 (char 4)

After a bit of noggin scratching (and perhaps a little mumbled cussing), I started thinking about the fact I had not upgraded my couchapp install since long before I last upgraded CouchDb.

Running the following cleared up all error and put me back in the happy land of  ‘couchapp push’:

“easy_install -U couchapp”

Yup… Just a version issue…  Hope this saves someone a few gray hairs…

 

-Matt