[password]123456[/password]
根据输入的显示值;获取选中的下拉Key: ----导入
public string GetCombValueByCaption(string fieldKey, string value)
{ //获取下拉值
string enumItemValue = "";
try
{
Field field = this.View.BusinessInfo.GetField(fieldKey);
ComboField comboField = field as ComboField;
var enumObj = (EnumObject) comboField.EnumObject;
//根据枚举值获取枚举项,然后拿枚举项的枚举名称
enumItemValue =
enumObj.Items.FirstOrDefault(
p =>
p.Caption.ToString().Equals(value.Trim())).Value.ToString();
}
catch (Exception exception)
{
}
return enumItemValue;
}
根据下拉选中的key 得到 显示的值: ----导出
public string GetCombCaptionByValue(string fieldKey, string value)
{ //获取下拉值
string enumItemValue = "";
try
{
Field field = this.View.BusinessInfo.GetField(fieldKey);
ComboField comboField = field as ComboField;
var enumObj = (EnumObject) comboField.EnumObject;
//根据枚举值获取枚举项,然后拿枚举项的枚举名称
enumItemValue =
enumObj.Items.FirstOrDefault(
p =>
p.Value.ToString().Equals(value.Trim())).Caption.ToString();
}
catch (Exception exception)
{
}
return enumItemValue;
}
[code] #region 下拉列表取值
///
/// 通过显示值取得下拉列表的Key
///
///
///
///
public static string GetCombValueByCaption(Field field, string captions)
{
//获取下拉值
string enumItemValue = "";
foreach (var caption in captions.Trim().Split(';'))
{
try
{
ComboField comboField = field as ComboField;
var enumObj = (EnumObject) comboField.EnumObject;
//根据枚举值获取枚举项,然后拿枚举项的枚举名称
enumItemValue =
enumObj.Items.FirstOrDefault(
p =>
p.Caption.ToString().Equals(caption.Trim())).Value.ToString().Trim() + ",";
}
catch (Exception exception)
{
enumItemValue = enumItemValue;
}
}
if (enumItemValue.Length > 0)
{
enumItemValue = enumItemValue.Substring(0, enumItemValue.Length - 1);
}
return enumItemValue;
}
///
/// 通过Key取得下拉列表的显示值
///
///
///
///
public static string GetCombCaptionByValue(Field field, string value)
{
//获取下拉值
string enumItemValue = "";
foreach (var key in value.Trim().Split(','))
{
try
{
ComboField comboField = field as ComboField;
var enumObj = (EnumObject) comboField.EnumObject; //根据枚举值获取枚举项,然后拿枚举项的枚举名称
enumItemValue +=
enumObj.Items.FirstOrDefault(
p =>
p.Value.ToString().Equals(key.Trim())).Caption.ToString().Trim() + ";";
}
catch (Exception exception)
{
enumItemValue = enumItemValue;
}
}
if (enumItemValue.Length > 0)
{
enumItemValue = enumItemValue.Substring(0, enumItemValue.Length - 1);
}
return enumItemValue;
}
#endregion[/code]
推荐阅读