473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dropdown databind to public enum

I'm trying to do this
http://geekswithblogs.net/jawad/arch...mDropDown.aspx

public enum Color
{
RED,
GREEN,
BLUE
}

protected System.Web.UI.WebControls.DropDownList ddColor;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ddColor.DataSource = Enum.GetNames(typeof(Color));
ddColor.DataBind();
}
}

private void ddColor_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Color selectedColor = (Color)Enum.Parse(ddColor.SelectedValue);
}

in vb, but I can't get the syntax of "ddColor.DataSource =
Enum.GetNames(typeof(Color));" correct!

Please help
Nov 19 '05 #1
2 1447
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not MyBase.IsPostBack Then
Me.ddColor.DataSource = Enum.GetNames(GetType(Color))
Me.ddColor.DataBind
End If
End Sub

Your event handler is wrong, however (missing one arg on the enum.parse):

Private Sub ddColor_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As
EventArgs)
Dim color1 As Color = CType(Enum.Parse(GetType(Color), _

ddColor.SelectedValue), Color)
End Sub

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
"wapsiii" wrote:
I'm trying to do this
http://geekswithblogs.net/jawad/arch...mDropDown.aspx

public enum Color
{
RED,
GREEN,
BLUE
}

protected System.Web.UI.WebControls.DropDownList ddColor;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ddColor.DataSource = Enum.GetNames(typeof(Color));
ddColor.DataBind();
}
}

private void ddColor_SelectedIndexChanged(object sender,
System.EventArgs e)
{
Color selectedColor = (Color)Enum.Parse(ddColor.SelectedValue);
}

in vb, but I can't get the syntax of "ddColor.DataSource =
Enum.GetNames(typeof(Color));" correct!

Please help

Nov 19 '05 #2
thanks :)

On Fri, 21 Oct 2005 12:59:03 -0700, "Cowboy (Gregory A. Beamer) - MVP"
<No************@comcast.netNoSpamM> wrote:
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not MyBase.IsPostBack Then
Me.ddColor.DataSource = Enum.GetNames(GetType(Color))
Me.ddColor.DataBind
End If
End Sub

Your event handler is wrong, however (missing one arg on the enum.parse):

Private Sub ddColor_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As
EventArgs)
Dim color1 As Color = CType(Enum.Parse(GetType(Color), _

ddColor.SelectedValue), Color)
End Sub

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kilic Beg via .NET 247 | last post by:
Hi, I am having trouble adding a dropdown to DataGrid at runtime. I create all boundColumns and the TemplateColumn for the dropdown at runtime. The dropdown has a different datasource then the...
2
by: msnews.microsoft.com | last post by:
How do I get Intellisense to open a dropdown list box for a method's parameters when the parameter is an ENUM? public class MyClass { public enum IDkind { PersonID, EntityID, PlaceID
8
by: Kris Rockwell | last post by:
Hello, I have done the following to bind data to a DropDown box: 1. Drag SQLServer table onto web form to create data connection and data adapter. 2. Generate dataset by right-clicking on...
2
by: Kevin Johnson | last post by:
H I have an ASP.NET datagrid written in C#. When editing my datagrid it contains one dropdown list and 4 normal textboxes I need the dropdown list to contain all of the colors in the...
0
by: Anthony | last post by:
So I've got three dropdowns in a datagrid footer (to add records). I need them to cascade, in the first one I have three choices, in the second one I have anywhere from 3 to 10 choices, depending...
1
by: Mike C | last post by:
I'm new to Web development so I'm doing some bootstrapping and would really appreciate any help. Been grappling with this for days and am utterly confused by all the information on the web. I have...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.