M
Mark Heimonen
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.EventType),
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.Log.EventType))
Dim objDataRow As DataRow = objDataTable.NewRow
objDataRow("EventTypeID") =
CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.EventType),
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
to bind a list of enums to a dropdownlist. Using
CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.EventType),
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.Log.EventType))
Dim objDataRow As DataRow = objDataTable.NewRow
objDataRow("EventTypeID") =
CType([Enum].Parse(GetType(ManagePointClassLibrary.Utils.Log.EventType),
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