[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Problem populating drop down list from enum

Posted on 2007-07-31
4
Medium Priority
?
1,198 Views
Last Modified: 2008-01-09
Hello experts
I'm having problems creating a web control. Hopefully you can helps.
Basically the web control is a drop down list that suppose to be populated with values from Enum.
I used to do this with Windows formes and it worked but ASP.NET gives me blank drop down when the page is launched.
So.. the code behind the web control:
public partial class Controls_States : System.Web.UI.UserControl
{
    public enum States
    {
        AL, AK, AZ, AR, CA, CO, CT, DE, DC, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME, MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC,
        ND, OH, OK, OR, PA, RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY, Canada, All
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ddlStates.DataSource = Enum.GetNames(typeof(States));
    }
}

When control used on the page it populates blank drop down list. What's wrong guys ?
0
Comment
Question by:techsuppoprt
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
Ashutosh Vyas earned 1000 total points
ID: 19606524
YOU FORGOT TO BIND IT. :)

protected void Page_Load(object sender, EventArgs e)
        {
            ddlStates.DataSource = Enum.GetNames(typeof(States));
            ddlStates.DataBind();
        }
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 19606537
ah sweet, it worked! Quick question though... Do I need to close any Data Binds for some reason at any point ?..Maybe when I switch to another page ?
( i'm learning )
0
 
LVL 8

Expert Comment

by:Ashutosh Vyas
ID: 19606552
i dont think so
0
 
LVL 1

Author Comment

by:techsuppoprt
ID: 19606649
Thank you very much!
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

873 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