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

Wow. I never use this thing. [Inception]

So, I came to post a quick quip about how much I liked Inception today and realized how little I use my blog anymore.  Not that I have ever been a competitive blogger or anything of the sort, but it would seem that I have withered and dried up – at least so far as these posts are concerned (and likely reflect).

None the less, that is not the case (me withering and drying) as I have just been really, really (really) busy reading and trying to get myself up to speed as a professional programmer… Something that I am enjoying emensely (even though it sometimes feels as if I will never ever (ever) know enough to take a breath again – GOOD THING IT’S SUPA FUN!).

Speaking of something I have recently enjoyed (and my reason for sitting down 15 mins ago to begin writing this) – watching Inception (I’ll wait while you see what it is if you don’t know)… Oddly, there is more related between the first part of this post (developing as a developer) and the fun provided by Inception – conceptually at least… I have to say, I was genuinely entertained at the layering and constant thought provoking representations of recursion and Big-O concepts… I won’t go into it much more than that, but if you find this stuff interesting, you will likely enjoy aspects of the movie that may perhaps will be overlooked by “other watchers” of Inception.  Funny thing is, I get back home, head over to browse hacker news and quickly come to the realization that I was not alone in my CS-centric thoughts about the film – http://news.ycombinator.com/item?id=1526104

Aside from the mentally stimulating representation of CS-Theory-related concepts, there is PLENTY of eye-candy by way of perty explosions and mind-bending (and physically defying) scenery to keep you entertained – even if the exotic applications of recursion aren’t your cup of tea.

I’d give Inception an ‘A’.

Practical Django Projects 2nd Ed. (Apress) – CH3 TinyMCE Problem

Updated: April 6, 2010 9:50pm CST – Correction (Below)

When reading/working through the 2nd edition of Apress’ ‘Practical Django Projects’, I hit a hang.  A big hang.  And like most big hangs, it was actually a very small (technically speaking) bump in the road.   The problem is that when looking to “how to” books such as ‘Practical Django Projects’, it is easy to fall back to the book’s printed text as the absolute code bible of what is and what is not correct in this world of code.  Unfortunatly, as was the case with me, this can lead to wasted hours and (after-the-fact) embarrassing frustration.

As I have seen this mentioned on forums around the interwebs while researching this myself, I figured I would document the solution here.  I am happy to say that I do not have to cite reference here as I figured this out myself and have submitted an errata report to the publisher.  What I am not as happy to admit is the fact that when you see what the problem here is, you will not be impressed (and will likely kick yourself as clearly you are reading this for help – and don’t really need it)…  So on to the meat…

PG.24-25 – the tiny_mce.js referral to load TinyMCE in your Flatpages… You set it up, just as the book instructs and BAM – nothing… No TinyMCE and a Firebug inspection of the page shows that the tiny_mce.js cannot be found (404).. Again, the error is actually quite simple, of course making it all the more simple to overlook when error correcting…

On page 24, the reader is instructed to set ‘document_root’:’/path/to/tiny_mce’.  In the explanatory following paragraph, the example directory “/Users/jbennett/javascript/TinyMCE/jscripts/tiny_mce” is given.

On page 25, the reader is told to set the TinyMCE script up on the template as follows: <script type=”text/javascript” src=”/tiny_mce/tiny_mce.js”></script>.  Since we already set the document_root (pg25) to ‘../jscripts/tiny_mce/’, the ‘tiny_mce” portion is not needed here and of course is not a valid src referral as the tiny_mce.js is located in ‘../tiny_mce/’ and not in ‘../tiny_mce/tiny_mce/.

Hope this helps someone…

UPDATE:  Ok, so stepping back to it today, I don’t know quite what I was thinking last night and am sorry to Apress for incorrectly identifying this supposed error.  In reworking through this, the text it 100% correct.  I am blaming the lack of sleep for my confusion (because that is less of an ego blow than blaming stupidity).  My misunderstanding came about from a ASSumption made by me on the meaning of document_root and the Javascript referral.  Reading this helped me better understand where the two meet (aka not a literal direct path relationship): How To Serve Static Files… The “How to do it” section pretty much sums it up 🙂  Sorry for my confusion!!!

Google Code University

Google Code UniversityI saw a posting about the Google Code University on Hacker News this morning.  A quick inspection of the site shows a nice set of tutorials on Python, C++, Java and Go.

I personally worked through  Google’s Python Class last night and found it to be easy to follow and relatively comprehensive on the basics – this one alone is enough for me to at least recommend a visit.

I really hope that there is more to come to the Code University in the near future!