如何将枚举绑定到DropDownList上

None.gif < HTML >
None.gif    
< HEAD >
None.gif        
< title > WebForm5 </ title >
None.gif        
< meta  content ="Microsoft Visual Studio .NET 7.1"  name ="GENERATOR" >
None.gif        
< meta  content ="C#"  name ="CODE_LANGUAGE" >
None.gif        
< meta  content ="JavaScript"  name ="vs_defaultClientScript" >
None.gif        
< meta  content ="http://schemas.microsoft.com/intellisense/ie5"  name ="vs_targetSchema" >
None.gif    
</ HEAD >
None.gif    
< BODY >
None.gif        
< form  id ="Form1"  method ="post"  runat ="server" >
None.gif            
< asp:DropDownList  id ="drpStatus"  style ="Z-INDEX: 101; LEFT: 248px; POSITION: absolute; TOP: 72px"
None.gif                runat
="server" ></ asp:DropDownList >
None.gif        
</ form >
None.gif    
</ BODY >
None.gif
</ HTML >
None.gif

None.gif using  System;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
using  System.Data.SqlClient;
None.gif
None.gif
namespace  Document
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Summary description for WebForm5.
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class WebForm5 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
protected System.Web.UI.WebControls.DropDownList drpStatus;
InBlock.gif        
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ListType();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void ListType()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            drpStatus.Items.Clear();
InBlock.gif            drpStatus.DataSource 
= ListTypeForEnum();
InBlock.gif            drpStatus.DataValueField 
= "value";
InBlock.gif            drpStatus.DataTextField 
= "text";
InBlock.gif            drpStatus.DataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public static IList ListTypeForEnum()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ArrayList list 
= new ArrayList();
InBlock.gif            
foreach (int i in Enum.GetValues(typeof(EnumActivityType)))
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ListItem listitem 
= new ListItem(Enum.GetName(typeof(EnumActivityType), i), i.ToString());
InBlock.gif                list.Add(listitem);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return list;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public enum EnumActivityType
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Task 
= 1,
InBlock.gif            Fax 
= 2,
InBlock.gif            Phone 
= 3,
InBlock.gif            Email 
= 4,
InBlock.gif            Reminder 
= 5,
InBlock.gif            Appointment 
= 6,
InBlock.gif            Expiration 
= 7,
InBlock.gif            Inquiry 
= 8
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

转载于:https://www.cnblogs.com/cheatlove/articles/405390.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值