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.
I have bit my tongue for 3 months now and just can’t do it anymore. Why in the hell is it that every time I turn on my PS3, I have to wait for 20 minutes before I can play a game. Were I 12, with little to do, I would likely give two shits less – cause, after all, I have dickall to do. I on the other hand, am not 12 and usually do have shiznit that I need to do – I usually grab a quick game or two of (INSERT GAME NAME HERE) in between doing said shiznit. But can I do that with my PS3? NO! Why? Cause every damned time I turn the fucker on it starts pulling the ever so important updates.
Really, what the effin-eff, Sony. I don’t understand why I have to pull a 5 part update every time I put a game in your SIX-HUNDRED DOLLAR CONSOLE (ok, so I have the Drake edition and some extras, but yea, $600 smackers), the damn thing steals 20 minutes of my life… I own a 360, I own a Wii – they don’t do this to me. So, a console ultimately made for children (Wii) and a console marketed as your direct competition to your console (360) both understand my needs as a gamer a whole lot more than you apparently do – wanna take a guess at what consoles get the largest percentage of my play time? I can give you a hint – they don’t have a P or and S in their name (unless you spell out numbers)…
So, I logged into my Hotmail account (aka the Spam Dump) and was surprised to find that Microsoft has stopped their blocking of Firefox for the “new” mailbox features…Â A long time user of Firefox, I have simply accepted the petty tactics of MS against Firefox users (it’s not just them, my bank does it too), but it seems that I no longer have to live my life as a second class Hotmail citizen.
For those with no knowledge of the issue, Microsoft has seemingly singled out Firefox users and prevented them from accessing the “Full” interface to Hotmail’s email service.Â Seemingly limited to Firefox, other browsers (IE & Opera – not sure about Safari) have been able to access the full functionality of Hotmail since its initial roll-out.Â Hotly debated in various circles, it is widely believed that the limiting of access to the “Full” functionality of Hotmail’s services were based not on browser computability, but instead merely on browser client branding alone (which is why some browser other than MSIE worked, while others did not).
I do not know what brought about the change of heart over at Microsoft – perhaps they are finally finding honey works better than vinegar? – none the less, I am ‘pleased’ (read as indifferent) to see Microsoft has decided that childishly blocking their service’s users from utilizing its full functionality is not a good business move.
Well, off to my sparkling new spam box’s interface!