locked
Is there any Fill dropdownList from Enum Class RRS feed

  • Question

  • User1710777909 posted

    Hai

    Is there any way to fill dropdown list from Enumeration that is Enum class

    For e.g I have the Report Types as Enum Class

    Public Enum ReportType

    PDF=1

    Crystal=2

    Excel=3

    End Enum 

    This Enum Class is there any way to bind in Dropdownlist

    Thanks

     

    Wednesday, August 19, 2009 9:39 AM

Answers

  • User-1360095595 posted

    Yes, you certainly can.  One way is using something like this:

    Array values = Enum.GetValues(typeof(ReportType));
    DropDownList1.DataSource = values;
    DropDownList1.DataBind();
    


    You can specify different DataTextField & DataValuField if you wish.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2009 10:50 AM
  • User1383809551 posted

    Hello ,

    Try this

    DropDownList1.DataSource = Enum.GetNames(typeof(MyEnum.ReportType));
    DropDownList1.DataBind();

    MyEnum is ur class name.


    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2009 10:56 AM

All replies

  • User-1360095595 posted

    Yes, you certainly can.  One way is using something like this:

    Array values = Enum.GetValues(typeof(ReportType));
    DropDownList1.DataSource = values;
    DropDownList1.DataBind();
    


    You can specify different DataTextField & DataValuField if you wish.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2009 10:50 AM
  • User1383809551 posted

    Hello ,

    Try this

    DropDownList1.DataSource = Enum.GetNames(typeof(MyEnum.ReportType));
    DropDownList1.DataBind();

    MyEnum is ur class name.


    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 19, 2009 10:56 AM
  • User1710777909 posted

    Thanks for your immediate reply

    I get an error message as ReportType is Type in BussinessClass.clsEnums and Cannot be used as an expression

     

    Thanks 

    Thursday, August 20, 2009 3:55 AM
  • User1383809551 posted

    Hello,

    try this

    DropDownList1.DataSource = Enum.GetNames(typeof(BussinessClass.clsEnums.ReportType));
    DropDownList1.DataBind();

    Make sure that u r giving correct class name where ReportType Enum is specified

    Thanks

    Thursday, August 20, 2009 11:41 AM
  • User1710777909 posted

    Thanks ratheesh for ur reply,

    I have given the same, and specified correctly but still errors appears like that

    Thanks 

    Saturday, August 22, 2009 6:01 AM
  • User1383809551 posted

    Hello

    It should work you might be doing something wrong..

    Could u post your Enum with the class .

    Thanks

    Saturday, August 22, 2009 6:34 PM
  • User1710777909 posted

    Here is My Code

    Public Class clsEnums

    Public Enum ReportType

    CrystalReport

    PDF

    Excel

     

    End Enum

    End Class

    // the above code/class is written in the Bussiness Layer

    In the Page

     

    Dim values As Array

     

    values = System.Enum.GetValues(TypeOf (clsEnums.ReportType) )

     

    ddReportType.DataSource = values

     

    ddReportype.DataBind()

     

    Sunday, August 23, 2009 12:33 AM
  • User1710777909 posted

    Thanks dear

    there was slight change [Enum].GetNames(typEnum)
    it works fine

     

    thanks 

    Sunday, January 17, 2010 4:11 AM