Solved

Get selected value from database to default on dropdown box

Posted on 2006-11-29
5
2,178 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now