I've just had to fix a colleagues code, which had the same problem that I'd been struggling with yesterday - it's another one of those annoying quirks that has you tearing your hair out because you look at your code and even though it compiles it still wont work.
The issue was that we are trying to populate a dropdown list dynamically - using the c# funtion
dropdownlist.items.add("Text","value");
Although this does compile it didn't seem to work - I stand to be corrected.
The way I got round it was to create a new listitem object and populate it with my text and value. i.e
dropdownlist.items.add(new ListItem("Text","value"));
Hope this helps somebody cus it's such an annoying thing to get stuck with - another point was that the value must always be a string - you can cast it when you retrieve it - (Convert.ToInt32(dropdownlist.selectedItem.value) but it seems to only want strings (I guess this is because the value is going to be rendered into HTML so any cast information will be obliterated anyway. A Little like the classic ASP Response.Write("Some HTML") used to work.
Blogged with Flock
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5