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 537691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:57:13+00:00 2026-05-13T09:57:13+00:00

The website I am working on will contain a drop-down list that shows a

  • 0

The website I am working on will contain a drop-down list that shows a number of reason codes.

Is it possible to populate a drop-down list with an array derived from a custom class?

Something like this:

ASPX Page

<asp:DropDownList ID="ddlReasonsWhy" runat="server"></asp:DropDownList>

ASPX Code Behind

protected void Page_Load(object sender, EventArgs e)
{
    //instantiate custom class
    Class1 reasonsList = new Class1();
   //populate reasons list
   this.ddlReasonsWhy.Items.Add(reasonsList.getReasons);

Custom Class

public string[] getReasons()
    {
        string[] Reasons;
        Reasons[0] = "test";
        Reasons[1] = "test2";
        Reasons[2] = "test3";

        return Reasons;
    }

UPDATE1:

Thanks to the answers and this stack link my final solution is similar to Ahmet and silky answers.

Class

 public List<ListItem> getRejectReasons()
    {
        List<ListItem> reasons = new List<ListItem>();
        reasons.Add(new ListItem("Select Value", "0"));
        reasons.Add(new ListItem("Red", "1"));
        reasons.Add(new ListItem("Green", "2"));
        return reasons;

    }

Code Behind

 //instantiate custom class
 Class1 reject = new Class1();
 this.ddlReasonsWhy.DataSource = reject.getRejectReasons();
 this.ddlReasonsWhy.DataBind();
  • 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-13T09:57:13+00:00Added an answer on May 13, 2026 at 9:57 am

    Use ListItem instead of string and Addrange for Add

    edit: getReasons is not a variable so use getReasons()

    ASPXPAGE

    <asp:DropDownList ID="ddlReasonsWhy" runat="server"></asp:DropDownList>
    

    ASPX Code Behind

    protected void Page_Load(object sender, EventArgs e)
    {
        //instantiate custom class
        Class1 reasonsList = new Class1();
       //populate reasons list
       this.ddlReasonsWhy.Items.AddRange(reasonsList.getReasons());
    }
    

    Custom Class

    public ListItem[] getReasons()
        {
            ListItem[] Reasons;
            Reasons[0] = "test";
            Reasons[1] = "test2";
            Reasons[2] = "test3";
    
            return Reasons;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a website that will be using Facebook Connect to authenticate users.
I'm working on a website that will use features of social networking (like facebook
I just started working on a website that will help people understand what rappers
I am currently working on a website that will have a high volume of
I'm working on an E-Book that will be published to my website. I want
I'm working on a website which will be hosting a number of books written
I'm working on a little something that will be part of an e-commerce website
A website I've been working on will not match data using a PHP (preg_match)
I am working on an website where users will have to pay a small
I am working on a online shopping website, it will have product images also.

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.