View Single Post
  #7 (permalink)  
Old March 13th, 2009, 01:27 AM
RushNP774 RushNP774 is offline
Authorized User
Join Date: Mar 2009
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts

Originally Posted by Lee Dumond View Post
Actually, looking at what you're trying to do a bit more closely, it looks like what you have is probably OK. From here, you should be able to simply bind the SelectedValue property of the DropDownList using two-way databinding, like this:
I tried that and pretty sure I entered it exactly as you typed it (copy & paste FTW). It compiled fine, but when I went to "edit" the record, I received this error:

[ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value]

I don't really know what that means, but it seems odd that the DDL couldn't find a value, because it was working fine before I put the Bind command in. I also tried:
  1. Entering a record manually and typed in a Category for it to see if the fact that the Category value for that item was NULL to begin with. No dice. Although I did figure out that the Bind in the ItemTemplate command works because I could see the value I typed in. I guess that's a plus.
  2. Moved SqlDataSource3 (the one populating my dropdown list) to the top of the page to see if for some reason the page wasn't populating the DDL because it hadn't arrived at it in the code yet. Didn't help either.
  3. Changed "Name" in the DataTextField="Name" DataValueField="Name" properties to "Category", and got a different error. I don't know what those properties really do, but I thought I'd try. I got a different error when I did that...
  4. Added AppendDataBoundItems="True" to the DDL, but that didn't help either.
  5. Added "<asp:ListItem Value="0">Select Category</asp:ListItem>" between the asp:DropDownList control to see if manually forcing a default value in there would help (and then let it populate from my other table after that), but that didn't help either.
Someone over on the MS forums had this same problem on this thread:, and some of the suggestions worked for some people, but not me.

The Beginning ASP.NET book makes all this stuff look so easy. I knew it sounded too good to be true . Oh well, I'll keep at it, because this should be an easy fix.