zoukankan      html  css  js  c++  java
  • 接口转换 数据库列表的内容 显示在datagrid

    public class AddressConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                string result = string.Empty;
    
                if (value != null)
                {
                    string[] CustomCode = value.ToString().Split(',');
    
                    for (int i = 0; i < CustomCode.Count(); i++)
                    {
                        var tempCustom = CodeListHelper.AllAddressList.Where(c => c.SelectValue == CustomCode[i]).FirstOrDefault();
    
                        if (i == 0)
                        {
                            if (tempCustom == null)
                            {
                                result = CustomCode[i];
                            }
                            else
                            {
                                result = tempCustom.DisplayValue;
                            }
                        }
                        else
                        {
                            if (tempCustom == null)
                            {
                                result += "," + CustomCode[i];
                            }
                            else
                            {
                                result += "," + tempCustom.DisplayValue;
                            }
                        }
                    }
    
                    return result;
    
                }
    
                return result;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    上面是转换活的例子,下面是转换死的例子

     public class CarTypeConverter : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value != null)
                {
                    var tempCustom = CodeListHelper.DispatchTypeList.Where(c => c.SelectValue == value.ToString()).FirstOrDefault();
    
                    if (tempCustom != null)
                    {
                        return tempCustom.DisplayValue;
                    }
                }
    
                return value;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                throw new NotImplementedException();
            }
        }

    说这个意思。

  • 相关阅读:
    HTML DOM教程 14HTML DOM Document 对象
    HTML DOM教程 19HTML DOM Button 对象
    HTML DOM教程 22HTML DOM Form 对象
    HTML DOM教程 16HTML DOM Area 对象
    ubuntu 11.04 问题 小结
    VC6.0的 错误解决办法 小结
    boot.img的解包与打包
    shell里 截取字符串
    从零 使用vc
    Imagemagick 对图片 大小 和 格式的 调整
  • 原文地址:https://www.cnblogs.com/Early-Bird/p/4269196.html
Copyright © 2011-2022 走看看