asp.net the numbers inside the enumeration file are bound to the DropDownList inside to go _ practical tips

Source: Internet
Author: User
Copy Code code as follows:

public class Appenum
{
public enum Pointlogtype:int
{
<summary>
Email Confirmation
</summary>
[Description ("Email confirmation")]
Recruit = 1,//new customer activation +
<summary>
Old Customer Feedback
</summary>
[Description ("Old customer feedback")]
Veteran = 2,//old customer shopping history reply
<summary>
Generate order
</summary>
[Description ("Generate order")]
Createorder = 3,//Place order-
<summary>
void order
</summary>
[Description ("Void Order")]
Abandonso = 5,//void order
<summary>
Cancellation of cancelled order
</summary>
[Description ("cancellation of Cancelled order")]
Cancelabandonso = 6,//audit void cancellation-
<summary>
Return
</summary>
[Description ("return")]
Returnproduct = 7,//Return-
<summary>
Cancel a return
</summary>
[Description ("Cancel return")]
Cancelreturn = 8,
<summary>
Cancel out of library
</summary>
[Description ("Cancel out of library")]
Canceloutstock = 9,//Cancel Shipment
<summary>
Integral transfer
</summary>
[Description ("Integral transfer")]
Transferpoint = 10,//integral transfer
<summary>
Shopping score
</summary>
[Description ("Shopping score")]
Addpointlater = 11,//Lag bonus
<summary>
Order modification
</summary>
[Description ("Order modification")]
Updateso = 12,//Modify Saleorder
<summary>
Wholesale Deduction
</summary>
[Description ("wholesale deduction")]
Wholesale = 13,//wholesale minus points-as if not used.
<summary>
Buy a card
</summary>
[Description ("buy card")]
Infoproduct = 14,//Buy card minus points-
<summary>
Other
</summary>
[Description ("other")]
Bizrequest =//request
<summary>
Merchandise comments Send points
</summary>
[Description ("Commodity Review Send Points")]
Remark =//remark
<summary>
Register to send points
</summary>
[Description ("Register to send Points")]
Newregister = 17,//register to send points
<summary>
DIY activities points increase or decrease
</summary>
[Description ("Increase or decrease of DIY activities")]
DIY =,//diy activity points increase or decrease, Chengdu DIY system, no use.
<summary>
System Transfer integral
</summary>
[Description (System transfer integral)]
Systransferpoint = 19,//SYSTEM account Neweggcs transfer points to customers
<summary>
System account Increase points
</summary>
[Description ("System account Increase integral")]
Addpointtosysaccounts = 20,//Finance add points to System account
<summary>
Take part in the quiz
</summary>
[Description ("Participation Quiz")]
Betreductpoint = 21,//betting use points
<summary>
Quiz income
</summary>
[Description ("quiz proceeds")]
Betaddpoint = 22,//Lottery points
<summary>
New user's first shopping gift points
</summary>
[Description ("New user's first shopping bonus points")]
Newcustomerfirstbuy = 23,//New registered user, first time shopping to send points
<summary>
Automatic Lifting Essence Gift points
</summary>
[Description ("Auto lift essence Bonus points")]
Setscoreauto = 24,//automatic lifting Essence gift points
<summary>
Add bonus points for marketing promotion activities
</summary>
[Description ("Add bonus points for marketing activities")]
Mktcampaign = 25,
<summary>
Expired Recycle points
</summary>
[Description ("Expired recycle points")]
Disusepoint =-1
}
}

Above is an enumerated list, how to read it? Using a DDR to bind it?
Copy Code code as follows:

Ddltype.displaymember = "Value";
Ddltype.valuemember = "Key";
Ddltype.datasource = Commonfunctions.getenumitems (typeof (Appenum.pointlogtype), false);
Ddltype.selectedvalue = 25; Default value

Here is the Getenumitems method in Commonfunctions:
Copy Code code as follows:

<summary>
Gets a list of all the items contained by the enumeration type.
</summary>
<param name= "Enumtype" > Enumeration type </param>
<param name= "Withall" > contains "all" </param>
<returns></returns>
public static list<enumitem> Getenumitems (Type enumtype, bool Withall)
{
list<enumitem> list = new list<enumitem> ();

if (Enumtype.isenum!= true)
{
Not an enumeration type
throw new InvalidOperationException ();
}

Include all option
if (Withall = = True)
List. ADD (New Enumitem (Appconst.intnull, "all"));

Get type information for attribute description
Type typedescription = typeof (DescriptionAttribute);

Gets the field information for the enumeration (because the value of the enumeration is actually the value of a static field)
system.reflection.fieldinfo[] fields = Enumtype.getfields ();

Retrieve all Fields
foreach (FieldInfo field in fields)
{
To filter out a value that is not enumerated, the source type of the enumeration is recorded
if (field. Fieldtype.isenum = = False)
Continue

Get the value of an enumeration by the name of the field
int value = (int) enumtype.invokemember (field. Name, Bindingflags.getfield, NULL, NULL, NULL);
string text = String. Empty;

To get all the custom attributes for this field, just look for the description feature
object[] arr = field. GetCustomAttributes (Typedescription, true);
if (arr. Length > 0)
{
Because the description custom attribute does not allow duplicates, it takes only the first
DescriptionAttribute AA = (DescriptionAttribute) arr[0];

To obtain a descriptive value for an attribute
Text = AA. Description;
}
Else
{
If there is no description of the feature, then the field name in English is displayed
Text = field. Name;
}
List. ADD (New Enumitem (value, text));
}

return list;
}
public class Enumitem
{
Private Object M_key;
Private object m_value;

public Object Key
{
get {return m_key;}
set {M_key = value;}
}

public Object Value
{
get {return m_value;}
set {m_value = value;}
}

Public Enumitem (Object _key, Object _value)
{
M_key = _key;
M_value = _value;
}
}
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.