Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:16:05+00:00 2026-05-23T06:16:05+00:00

This is my aspx <asp:Content ID=Content2 ContentPlaceHolderID=ContentPlaceHolder1 runat=server> <asp:ObjectDataSource ID=DSCategories runat=server SelectMethod=GetCategories TypeName=BAL.CategoryBAL> </asp:ObjectDataSource>

  • 0

This is my aspx

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:ObjectDataSource ID="DSCategories" runat="server" 
        SelectMethod="GetCategories" TypeName="BAL.CategoryBAL">
    </asp:ObjectDataSource>

    <div id="Criteria">
        <h3>Category:</h3>
        <asp:DropDownList ID="ddlCategories" runat="server" 
            DataSourceID="DSCategories" DataTextField="Description" 
            DataValueField="Code">
        </asp:DropDownList>
        <asp:Button ID="btnSetCriteria" runat="server" Text="Set Criteria" />

    </div>

</asp:Content>

And this is briefly my Page_Load code:

SearchCriteriaBAL scb = SearchCriteriaBAL.GetSearchCriteria(id);

string cat = String.Empty;
if (!string.IsNullOrEmpty(scb.Criteria))
{
    cat = ParseCriteria(scb.Criteria);

    ddlCategories.SelectedValue = cat;
}

I break on the SelectedValue assignment line and see the items in the dropdownlist and I see a valid value for cat and it is in the list but I get:

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

It seems to be doing the GetCategories AFTER I set the selectedValue and then it dies.

I placed it on its own test page for fear of interaction but it still fails. Has anyone seen this before?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:16:06+00:00Added an answer on May 23, 2026 at 6:16 am

    Write the function on DropDownList’s DataBound event instead of Page_Load

    Occurs after the server control binds
    to a data source.

    <asp:DropDownList ID="ddlCategories" runat="server" 
        DataSourceID="DSCategories" 
        DataTextField="Description" 
        DataValueField="Code"
        OnDataBound="ddlCategories_DataBound">
    </asp:DropDownList>
    

    Rather than using SelectedValue, I would have opted

    ddlCategories.Items.FindByValue(cat.Trim()).Selected = true;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a my Default.aspx page (with unnecessary details excised): <asp:Content ID=Content1 ContentPlaceHolderID=ContentPlaceHolder1 Runat=Server> <div
I have a this aspx-code: (sample) <asp:DropDownList runat=server ID=ddList1></asp:DropDownList> With this codebehind: List<System.Web.UI.WebControls.ListItem> colors
This is what I have in the aspx page: <head runat=server> <title>Website - <asp:ContentPlaceHolder
Let's say I have an aspx page with this calendar control: <asp:Calendar ID=Calendar1 runat=server
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat
I have code like this on some aspx page in my Web Application: <asp:Content
Language: asp This is sample of my code: str = www.example.com/gotobuy.aspx?id=1234 key_word = .obuy.
I have an Asp .net page like this simple one http://issamsoft.com/app2/page1.aspx and I want
This is what I'm talking about: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/ComboBox/ComboBox.aspx basically I want to have a drop
I tried to create this by following the video at http://www.asp.net/learn/videos/video-7026.aspx where Joe Stagner

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.