Ask a Question related to ASP.NET General, Design and Development.
-
Mark Heimonen #1
Binding enum values alphabetically to a drop down list
I haven't worked with enum types that much, and I wrote the following code
to bind a list of enums to a dropdownlist. Using
CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
strEventType), Integer).ToString is horrible to read, and probably not that
efficient either. Does anybody know a more elegant approach to this
problem?
Dim strEventType As String
For Each strEventType In
[Enum].GetNames(GetType(ManagePointClassLibrary.Utils.Lo g.EventType))
Dim objDataRow As DataRow = objDataTable.NewRow
objDataRow("EventTypeID") =
CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
strEventType), Integer).ToString
objDataRow("EventType") = strEventType
objDataTable.Rows.Add(objDataRow)
objDataRow.AcceptChanges()
Next
objDataView = New DataView()
objDataView = objDataTable.DefaultView
objDataView.Sort = "EventType"
eventtype.DataSource = objDataView
eventtype.DataTextField = "EventType"
eventtype.DataValueField = "EventTypeID"
eventtype.DataBind()
Thanks,
Mark Heimonen
Mark Heimonen Guest
-
wsdl changes enum values with [Flags]
If I declare a enum with the attribute like: public enum XXX {a=0,b=1,c=2} Then I use this enum in a web service, the generated wsdl code... -
Need help in binding data to datagrid by using drop down list
Hi all, I am new in asp.net, i encounter some problems in using drop down list and datagrid. I have manage to bind the data into datagrid but i... -
Binding WS to the List Component
I'm having some trouble with binding a web service to a list component and would appreciate some help... I've written a simple CFC to use as a... -
Dynamical populating a list that can be used as drop down list
Hi, I have a solution in which a person can be a member of one or more groups. In this case the groups are those used in the protection schema of... -
note 33904 added to function.fdf-enum-values
If you need something like this in a pre 4.3 version, here is a rough hack I was working on before I realized I didn't need this after all. ... -
John Saunders #2
Re: Binding enum values alphabetically to a drop down list
Mark,
You can't do much better than this because the ASP.NET DropDownList can only
handle string values (as opposed to the Windows Forms DropDownList, which
can handle arbitrary objects).
About the only thing you can do is to ignore the integer value entirely. Let
the DropDownList use EventType for both the DataTextField and
DataValueField. When you need a value (perhaps in the SelectedIndexChanged
event), _then_ use Enum.Parse to get the value as your Enum type.
--
John Saunders
Internet Engineer
[email]john.saunders@surfcontrol.com[/email]
"Mark Heimonen" <markh@adiaim.com> wrote in message
news:%23Xx5hwEWDHA.2368@TK2MSFTNGP09.phx.gbl...that> I haven't worked with enum types that much, and I wrote the following code
> to bind a list of enums to a dropdownlist. Using
> CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
> strEventType), Integer).ToString is horrible to read, and probably not> efficient either. Does anybody know a more elegant approach to this
> problem?
>
> Dim strEventType As String
> For Each strEventType In
> [Enum].GetNames(GetType(ManagePointClassLibrary.Utils.Lo g.EventType))
> Dim objDataRow As DataRow = objDataTable.NewRow
> objDataRow("EventTypeID") =
> CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
> strEventType), Integer).ToString
> objDataRow("EventType") = strEventType
> objDataTable.Rows.Add(objDataRow)
> objDataRow.AcceptChanges()
> Next
> objDataView = New DataView()
> objDataView = objDataTable.DefaultView
> objDataView.Sort = "EventType"
> eventtype.DataSource = objDataView
> eventtype.DataTextField = "EventType"
> eventtype.DataValueField = "EventTypeID"
> eventtype.DataBind()
>
> Thanks,
>
> Mark Heimonen
>
>
John Saunders Guest
-
Mark Heimonen #3
Re: Binding enum values alphabetically to a drop down list
Thanks,
Yeah, I think ignoring the integer value entirely is a good step up
performance-wise.
Mark Heimonen
Developer
Adia Information Management Corporation
"John Saunders" <john.saunders@surfcontrol.com> wrote in message
news:uRNyLEfWDHA.2352@TK2MSFTNGP12.phx.gbl...only> Mark,
>
> You can't do much better than this because the ASP.NET DropDownList canLet> handle string values (as opposed to the Windows Forms DropDownList, which
> can handle arbitrary objects).
>
> About the only thing you can do is to ignore the integer value entirely.code> the DropDownList use EventType for both the DataTextField and
> DataValueField. When you need a value (perhaps in the SelectedIndexChanged
> event), _then_ use Enum.Parse to get the value as your Enum type.
> --
> John Saunders
> Internet Engineer
> [email]john.saunders@surfcontrol.com[/email]
>
>
> "Mark Heimonen" <markh@adiaim.com> wrote in message
> news:%23Xx5hwEWDHA.2368@TK2MSFTNGP09.phx.gbl...> > I haven't worked with enum types that much, and I wrote the following> that> > to bind a list of enums to a dropdownlist. Using
> > CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
> > strEventType), Integer).ToString is horrible to read, and probably not>> > efficient either. Does anybody know a more elegant approach to this
> > problem?
> >
> > Dim strEventType As String
> > For Each strEventType In
> > [Enum].GetNames(GetType(ManagePointClassLibrary.Utils.Lo g.EventType))
> > Dim objDataRow As DataRow = objDataTable.NewRow
> > objDataRow("EventTypeID") =
> > CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.E ventType),
> > strEventType), Integer).ToString
> > objDataRow("EventType") = strEventType
> > objDataTable.Rows.Add(objDataRow)
> > objDataRow.AcceptChanges()
> > Next
> > objDataView = New DataView()
> > objDataView = objDataTable.DefaultView
> > objDataView.Sort = "EventType"
> > eventtype.DataSource = objDataView
> > eventtype.DataTextField = "EventType"
> > eventtype.DataValueField = "EventTypeID"
> > eventtype.DataBind()
> >
> > Thanks,
> >
> > Mark Heimonen
> >
> >
>
Mark Heimonen Guest



Reply With Quote

