Silently note the various usages of enumerations

Source: Internet
Author: User

Work is often encountered in the use of enumeration, of course, the use of the foreground page enumeration is mostly direct calls, and design to the background of the management often use the enumeration as a 1 collection to be used

list<fineui.listitem> Albumtype = new list<fineui.listitem> ();

foreach (Demandstatus type in Enum.getvalues (typeof (Demandstatus)))
{
Albumtype.add (New Fineui.listitem (type. ToString (), ((int) type). ToString ()));
}
This.ddl_status. DataSource = Albumtype;
This.ddl_status. DataTextField = "Text";
This.ddl_status. DataValueField = "Value";
This.ddl_status. DataBind ();

For example, here the binding enumeration to 1 DropDownList is a traversal of the ' demandstatus ' value in this enumeration is used

And in general, it just needs to be used directly.

Demandstatus. Normal

There is also the need to use the <%# GetDate ("status") if the value of the database encountered in development needs to be replaced by your enumeration%>

To bind in turn

Protected string GetDate (string status)
{

foreach (Productstatus item in Enum.getvalues (typeof (Productstatus)))
{
if (Convert.ToInt32 (status) = = Convert.ToInt32 (item))
{
return item. ToString ();
}
}
return string. Empty;
}

Silently note the various usages of enumerations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.