Avatar of JT_SIRO
JT_SIRO

asked on 

Dropdown box errors on Databind when no records are returned

I have a drop down box that causes the following error when I bind it to a datasource that returns no records.

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

What's the work-around here?

Here's my code - it bombs on the last line:
            // Fill DropDownList with Jobs and add All as a selection option
            SHATutil shat = new SHATutil();
            ddJob.DataSource = shat.GetUserJobs(Profile.UserName);
            ddJob.DataTextField = "JobName";
            ddJob.DataValueField = "JobName";
            ddJob.DataBind();
ASP.NET.NET ProgrammingC#

Avatar of undefined
Last Comment
starlite551
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

You must have set the selected value in the drop down in the aspx markup.
Avatar of Tom Beck
Tom Beck
Flag of United States of America image

Or somewhere else in the code behind?
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you sure you are not setting the selectedvalue for the dropdown somewhere else in your code?
ASKER CERTIFIED SOLUTION
Avatar of starlite551
starlite551
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo