Solved

Get selected value from database to default on dropdown box

Posted on 2006-11-29
5
2,181 Views
Last Modified: 2008-01-09
Hi have a dropdown box which needs to display either 0, 3 or 9 depending on what is selected in the database. I have it saving ok when someone submits the form, but when it reloads the form up, it doesnt default to the last selection, which i need it to do. The only problem is, its in a datagrid, so there are lots of these dropdown boxes.
Here is my code:-

<asp:TemplateColumn HeaderText="Score">
<ItemTemplate>
<asp:DropDownList id="Score" runat="server"  selectedindex='<%# DataBinder.Eval(Container.DataItem, "score") %>'>
<asp:ListItem Value="0">0</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>

the program runs a stored procedure which gets the value for score, but comes up with the error
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: value
pointing to :-
<asp:DropDownList id="Score" runat="server"  selectedindex='<%# DataBinder.Eval(Container.DataItem, "score") %>'>
Line 20:                                     <asp:ListItem Value="0">0</asp:ListItem>
Line 21:                                     <asp:ListItem Value="3">3</asp:ListItem>


any help appreciated!

0
Comment
Question by:richmorl
5 Comments
 
LVL 9

Expert Comment

by:peterdungan
ID: 18036844
add this attribute to the dropdownlist:

Text='<%# Bind("field name goes here") %>'
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 18037299
It sounds like you aren't checking for Page.IsPostBack before loading data into the DropDownList.

Bob
0
 
LVL 4

Accepted Solution

by:
satish_nagdev earned 500 total points
ID: 18042541
make sure there is item in list corresponding to value you are getting from db, might be null is getting returned or so.

thanks.
satish
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question