我正在使用枚举
public enum WatchUsageMode
{
Watch = 1,
EmailPreferences = 2
}
我想在我的视图状态中设置该枚举的属性,以便每当视图状态为null时返回Watch else EmailPreference.how我可以获取并设置属性吗?
答案 0 :(得分:2)
创建一个属性来封装此
public WatchUsageMode WatchUsageModeValue
{
get
{
if(ViewState["WatchUsageModeValue"] != null &&
ViewState["WatchUsageModeValue"] is WatchUsageMode)
return (WatchUsageMode)ViewState["WatchUsageModeValue"];
else
return null;
}
set
{
ViewState["WatchUsageModeValue"] = value;
}
}
答案 1 :(得分:0)
环境:
ViewState["KeyString"] = WatchUsageMode.EmailPreferences
从视图状态获取
WatchUsageMode get()
{
if(ViewState["KeyString"]!=null)
return (WatchUsageMode)ViewState["KeyString"];
return WatchUsageMode.Watch;
}