• C#代码总结03---通过获取类型,分类对前台页面的控件进行赋值操作


    该方法: 一般用于将数据库中的基本信息字段显示到前台页面对应的字段控件中

    private void InitViewZc(XxEntity model)
        {
            foreach (var info in model.GetType().GetProperties())
            {
                if (info.GetValue(model, null) != null && "EntityState" != info.Name && "EntityKey" != info.Name)
                {
                    TextBox cTb = (TextBox)FindControl(info.Name + "Tb");
                    TextBox Ipt = (TextBox)FindControl(info.Name + "Ipt");
                    TextBox Dec = (TextBox)FindControl(info.Name + "Dec");
                    DropDownList cDdl = (DropDownList)FindControl(info.Name + "Ddl");
                    RadioButtonList cRbl = (RadioButtonList)FindControl(info.Name + "Rbl");
                    if (cTb != null)
                    {
                        cTb.Text = info.GetValue(model, null).ToString();
                    }
                    if (Ipt != null)
                    {
                        Ipt.Text = Convert.ToDateTime(info.GetValue(model, null)).ToString("yyyy-MM-dd");
                    }
                    if (Dec != null)
                    {
                        Dec.Text = info.GetValue(model, null).ToString();
                    }
                    if (cDdl != null)
                    {
                        cDdl.Text = info.GetValue(model, null).ToString();
                    }
                    if (cRbl != null)
                    {
                        cRbl.Text = info.GetValue(model, null).ToString();
                    }
                }
            }
        }

    三个 TextBox控件适用于区分 String,Datetime,Decimal 三种类型格式。

  • 相关阅读:
    异常显示页面
    SpringBoot项目打包的两种类型1-WAR方式
    SpringBoot项目打包的两种类型1-JAR方式
    Spring Boot项目打包部署
    json转义处理
    xadmin使用
    nginx 反向代理
    python 队列、栈
    Django logging配置
    Tensorflow学习教程------普通神经网络对mnist数据集分类
  • 原文地址:https://www.cnblogs.com/JesseP/p/10681236.html
Copyright © 2020-2023  润新知