根据枚举获取下拉列表

本文介绍了一种将枚举类型转化为JSON字符串的方法,并展示了如何利用这些JSON数据填充ComboBox控件,实现单据状态的选择功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BLL:

//得到查验信息推送状态
public string GetEnumStationPushState(EnumStationPushState en)
{
FieldInfo fi = en.GetType().GetField(en.ToString());

object[] attrs = fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs != null && attrs.Length > 0)
{
return ((DescriptionAttribute)attrs[0]).Description;
}
else
{
return en.ToString();
}
}

一般处理程序:

//查验信息推送状态
public void GetChaYanstate(HttpContext context)
{
List<CommonModel> list = new List<CommonModel>();
int index = 1;
foreach (int i in Enum.GetValues(typeof(EnumStationPushState)))
{
CommonModel model = new CommonModel();
model.Id = index;
model.Name = _dsmb.GetEnumStationPushState((EnumStationPushState)i);
model.Value = i.ToString();
list.Add(model);
index++;
}
jsonstring = JsonConvert.SerializeObject(list);

if (!string.IsNullOrEmpty(jsonstring))
{
HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddSeconds(-1);
HttpContext.Current.Response.Expires = -1;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write(jsonstring);
HttpContext.Current.Response.End();
}
}

注:EnumStationPushState 枚举名

/// <summary>
/// 公共的使用类
/// </summary>
public class CommonModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Value { get; set; }
}

 

前台:

//单据状态
var GetBillStatusEnum = new Ext.data.JsonStore({
root: '', idProperty: 'Value', remoteSort: true,
baseParams: { Type: "GetChaYanstate" },
fields: ['Value', 'Name'],
proxy: new Ext.data.HttpProxy({
url: '../../DAC/Data/GetEnum.ashx', method: 'GET'
})
});

 

//单据状态
var danjuState = new Ext.form.ComboBox({
xtype: 'combo', fieldLabel: '单据状态', name: 'planstate',
id: 'planstate', lazyRender: true, mode: 'local', width: 130,
triggerAction: 'all', valueField: 'Value', displayField: 'Name', emptyText: '--单据状态--', blankText: '--单据状态--',
store: GetBillStatusEnum,
});

转载于:https://www.cnblogs.com/wuweierzhi/p/8854840.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值