当前位置: 首页>>代码示例>>C#>>正文


C# HtmlSelectBuilder类代码示例

本文整理汇总了C#中System.Web.UI.HtmlControls.HtmlSelectBuilder的典型用法代码示例。如果您正苦于以下问题:C# HtmlSelectBuilder类的具体用法?C# HtmlSelectBuilder怎么用?C# HtmlSelectBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HtmlSelectBuilder类属于System.Web.UI.HtmlControls命名空间,在下文中一共展示了HtmlSelectBuilder类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetChildControlType

//引入命名空间
using System;
using System.Security.Permissions;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace Samples.AspNet.CS.Controls
{
        // Define a type of child control for the custom HtmlSelect control.
    public class MyOption1
    {
        string _id;
        string _value;
        string _text;

        public string optionid
        {
            get
            { return _id; }
            set
            { _id = value; }
        }

        public string value
        {
            get
            { return _value; }
            set
            { _value = value; }
        }

        public string text
        {
            get
            { return _text; }
            set
            { _text = value; }
        }
    }

       // Define a type of child control for the custom HtmlSelect control.
    public class MyOption2
    {
        string _id;
        string _value;
        string _text;

        public string optionid
        {
            get
            { return _id; }
            set
            { _id = value; }
        }

        public string value
        {
            get
            { return _value; }
            set
            { _value = value; }
        }

        public string text
        {
            get
            { return _text; }
            set
            { _text = value; }
        }
    }

    // Define a custom HtmlSelectBuilder control.
    public class MyHtmlSelectBuilder : HtmlSelectBuilder
    {
        [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
        public override Type GetChildControlType(string tagName, IDictionary attribs)
        {
            // Distinguish between two possible types of child controls.
            if (tagName.ToLower().EndsWith("myoption1"))
            {
                return typeof(MyOption1);
            }
            else if (tagName.ToLower().EndsWith("myoption2"))
            {
                return typeof(MyOption2);
            }
            return null;
        }
    }

    [ControlBuilderAttribute(typeof(MyHtmlSelectBuilder))]
    public class CustomHtmlSelect : HtmlSelect
    {
        
        // Override AddParsedSubObject to treat the two types
        // of child controls differently.
        protected override void AddParsedSubObject(object obj)
        {
            string _outputtext;
            if (obj is MyOption1)
            {
                _outputtext = "option group 1: " + ((MyOption1)obj).text;
                ListItem li = new ListItem(_outputtext, ((MyOption1)obj).value);
                base.Items.Add(li);
            }
            if (obj is MyOption2)
            {
                _outputtext = "option group 2: " + ((MyOption2)obj).text;
                ListItem li = new ListItem(_outputtext, ((MyOption2)obj).value);
                base.Items.Add(li);
            }
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Web.UI.HtmlControls,代码行数:118,代码来源:HtmlSelectBuilder


注:本文中的System.Web.UI.HtmlControls.HtmlSelectBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。