C#生成HTML控件 代码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jsyhello/article/details/6310341

试用登录http://121.18.78.216/
        #region 生成控件
        /// <summary>
        /// table
        /// </summary>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlTable()
        {
            HtmlGenericControl control = new HtmlGenericControl("table");
            control.EnableViewState = false;
            control.Attributes.Add("cellpadding", "0");
            control.Attributes.Add("cellspacing", "0");
            return control;
        }
        /// <summary>
        /// img
        /// </summary>
        /// <param name="url"></param>
        /// <param name="title"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlImg(string url, string title)
        {
            HtmlGenericControl control = new HtmlGenericControl("img");
            control.EnableViewState = false;
            control.Attributes.Add("src", GetUrl(url));
            if (!String.IsNullOrEmpty(title))
            {
                control.Attributes.Add("title", title);
                control.Attributes.Add("alt", title);
            }
            control.Attributes.Add("bolder", "0");
            return control;
        }
        /// <summary>
        /// a
        /// </summary>
        /// <param name="url"></param>
        /// <param name="title"></param>
        /// <param name="target"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlA(string url, string title, string target)
        {
            HtmlGenericControl control = new HtmlGenericControl("a");
            control.EnableViewState = false;
            if (String.IsNullOrEmpty(title))
            {
                control.InnerHtml = "链接";
            }
            else
            {
                control.InnerHtml = title;
            }
            control.Attributes.Add("target", target);
            if (String.IsNullOrEmpty(url))
            {
                control.Disabled = true;
            }
            else
            {
                control.Attributes.Add("href", GetUrl(url));
            }
            return control;
        }
        /// <summary>
        /// input
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlInput(string id, string value, string width)
        {
            HtmlGenericControl control = new HtmlGenericControl("input");
            control.EnableViewState = false;
            if (!String.IsNullOrEmpty(id))
            {
                control.Attributes.Add("id", id);
                control.Attributes.Add("name", id);
            }
            if (!String.IsNullOrEmpty(value) && !value.Equals("%"))
            {
                control.Attributes.Add("value", value);
            }
            SetWidth(control, width);
            return control;
        }
        /// <summary>
        /// input text
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <param name="width"></param>
        /// <param name="maxlength"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlText(string id, string value, string width, int maxlength)
        {
            HtmlGenericControl control = GetHtmlInput(id, value, width);
            control.Attributes.Add("type", "text");
            if (maxlength > 0)
            {
                control.Attributes.Add("maxlength", maxlength.ToString());
            }
            return control;
        }
        /// <summary>
        /// area
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <param name="width"></param>
        /// <param name="rows"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlArea(string id, string value, string width, string rows)
        {
            HtmlGenericControl control = new HtmlGenericControl("textarea");
            control.EnableViewState = false;
            if (!String.IsNullOrEmpty(id))
            {
                control.Attributes.Add("id", id);
                control.Attributes.Add("name", id);
            }
            if (!String.IsNullOrEmpty(value) && !value.Equals("%"))
            {
                control.InnerHtml = value;
            }
            control.Attributes.Add("rows", DataHelper.GetIntValue(rows, 10).ToString());
            SetWidth(control, width);
            return control;
        }
        /// <summary>
        /// input button
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlButton(string id, string value, string width)
        {
            HtmlGenericControl control = GetHtmlInput(id, value, width);
            control.Attributes.Add("type", "button");
            return control;
        }
        /// <summary>
        /// 生成图片按钮 如图片不存在则为普通按钮
        /// </summary>
        /// <param name="id"></param>
        /// <param name="imgSrc"></param>
        /// <param name="title"></param>
        /// <param name="width"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetImageButton(string id, string imgSrc, string title, string width)
        {
            HtmlGenericControl control = new HtmlGenericControl("input");
            control.EnableViewState = false;
            if (!String.IsNullOrEmpty(id))
            {
                control.Attributes.Add("id", id);
                control.Attributes.Add("name", id);
            }
            if (!String.IsNullOrEmpty(title))
            {
                control.Attributes.Add("value", title);
            }
            if (String.IsNullOrEmpty(imgSrc))
            {
                control.Attributes.Add("type", "button");
            }
            else
            {
                control.Attributes.Add("type", "image");
                control.Attributes.Add("src", GetRootPath() + imgSrc.TrimStart('/'));
                if (!String.IsNullOrEmpty(title))
                {
                    control.Attributes.Add("title", title);
                }
            }
            SetWidth(control, width);
            return control;
        }
        /// <summary>
        /// input checkbox
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlCheckBox(string id, string value)
        {
            HtmlGenericControl control = GetHtmlInput(id, null, null);
            control.Attributes.Add("type", "checkbox");
            if (!String.IsNullOrEmpty(value))
            {
                control.Attributes.Add("checked", "true");
            }
            return control;
        }
        /// <summary>
        /// select
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        /// <param name="width"></param>
        /// <param name="selects">标题值的集合 值做展示内容</param>
        /// <returns></returns>
        public static HtmlGenericControl GetHtmlSelect(string id, string value, string width, NameValueCollection selects)
        {
            HtmlGenericControl control = new HtmlGenericControl("select");
            control.EnableViewState = false;
            if (!String.IsNullOrEmpty(id))
            {
                control.Attributes.Add("id", id);
                control.Attributes.Add("name", id);
            }
            SetWidth(control, width);
            if (selects != null)
            {
                for (int i = 0; i < selects.Count; i++)
                {
                    HtmlGenericControl option = new HtmlGenericControl("option");
                    option.EnableViewState = false;
                    option.Attributes.Add("value", selects.GetKey(i));
                    option.InnerHtml = selects.Get(i).Replace(" ", "&nbsp;&nbsp;");
                    if (selects.GetKey(i) == value)
                    {
                        option.Attributes.Add("selected", "selected");
                    }
                    control.Controls.Add(option);
                }
            }
            return control;
        }
        /// <summary>
        /// 获得span
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static HtmlGenericControl GetSpan(string text)
        {
            HtmlGenericControl control = new HtmlGenericControl("span");
            control.EnableViewState = false;
            if (!String.IsNullOrEmpty(text))
            {
                control.InnerHtml = text;
            }
            return control;
        }
        /// <summary>
        /// 获取文字控件
        /// </summary>
        /// <param name="text">文字值</param>
        /// <returns></returns>
        public static Literal GetLiteral(string text)
        {
            Literal lit = new Literal();
            lit.EnableViewState = false;
            lit.Text = text;
            return lit;
        }
        /// <summary>
        /// 获取空格控件
        /// </summary>
        /// <returns></returns>
        public static Literal GetSpace()
        {
            Literal lit = new Literal();
            lit.EnableViewState = false;
            lit.Text = Constants.NORMAL_SPACE;
            return lit;
        }
        /// <summary>
        /// 获得div
        /// </summary>
        /// <param name="isCenter">是否居中</param>
        /// <param name="control">放置控件</param>
        /// <returns></returns>
        public static HtmlGenericControl GetDiv(bool isCenter, Control control)
        {
            HtmlGenericControl div = new HtmlGenericControl("div");
            div.EnableViewState = false;
            if (isCenter)
            {
                div.Attributes.Add("align", "center");
            }
            if (control != null)
            {
                div.Controls.Add(control);
            }
            return div;
        }
        #endregion

 

C#开发的WEB开发的简单框架 节省开发信息管理系统时间 提高开发效率

构建一个WEB开发的基础框架(主要包括数据库处理、页面框架及工具类),形成ASP.NET信息管理系统快速开发架构。
一、框架实现了基于XML定制的列表查询及图表展现
二、列表实现了复杂查询条件、合并行列(分组求和的处理)、汇总行及钻取数据和图表的钻取
三、编辑配置支持单表数据的增加和修改,针对开发人员实现的编辑页面可方便扩展主表新增字段
使开发人员专注于系统的业务实现,节省开发时间,提高开发效率

试用登录http://121.18.78.216/

您看到的研发管理平台我只用了一个月的时间(还只是正常工作8小时以外的时间)做出来的。
所以自己觉得自己之前开发的用XML配置实现界面的开发架构,可以使开发人员专注于业务实现,提高信息管理系统开发效率

展开阅读全文

没有更多推荐了,返回首页