HtmlSelectBuilder クラスとは? わかりやすく解説

HtmlSelectBuilder クラス

メモ : このクラスは、.NET Framework version 2.0新しく追加されたものです。

パーサーやり取りして、HtmlSelect コントロール作成します

名前空間: System.Web.UI.HtmlControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class HtmlSelectBuilder
    Inherits ControlBuilder
Dim instance As HtmlSelectBuilder
public class HtmlSelectBuilder : ControlBuilder
public ref class HtmlSelectBuilder : public
 ControlBuilder
public class HtmlSelectBuilder extends ControlBuilder
public class HtmlSelectBuilder extends
 ControlBuilder
解説解説
使用例使用例

HtmlSelect カスタム コントロール<option> 子要素2 つの型定義してそれぞれの型を別々に処理するHtmlSelectBuilder カスタム コントロール作成する方法次のコード例示します

<%@ Page Language="VB"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls"
 Assembly="Samples.AspNet.VB"
 %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>HtmlSelectBuilder Example</title>
</head>
  <body>
    <form id="Form1" runat="server">
      <h3>HtmlSelectBuilder Example</h3>

      <aspSample:CustomHtmlSelect
       id="customhtmlselect1"
       runat="server">
      <aspSample:MyOption1 optionid="option1" value="1"
 text="item 1"/>
      <aspSample:MyOption1 optionid="option2" value="2"
 text="item 2"/>
      <aspSample:MyOption2 optionid="option3" value="3"
 text="item 3"/>
      <aspSample:MyOption2 optionid="option4" value="4"
 text="item 4"/>
      </aspSample:CustomHtmlSelect>

    </form>

  </body>

</html>
<%@ Page Language="C#"%>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls"
 Assembly="Samples.AspNet.CS" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html  >
<head runat="server">
    <title>HtmlSelectBuilder Example</title>
</head>
  <body>
    <form id="Form1" runat="server">
      <h3>HtmlSelectBuilder Example</h3>

      <aspSample:CustomHtmlSelect
       id="customhtmlselect1"
       runat="server">
      <aspSample:MyOption1 optionid="option1" value="1" text="item
 1"/>
      <aspSample:MyOption1 optionid="option2" value="2" text="item
 2"/>
      <aspSample:MyOption2 optionid="option3" value="3" text="item
 3"/>
      <aspSample:MyOption2 optionid="option4" value="4" text="item
 4"/>
      </aspSample:CustomHtmlSelect>

    </form>

  </body>

</html>
Imports System
Imports System.Security.Permissions
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace Samples.AspNet.VB.Controls
    ' Define a type of child control for the custom HtmlSelect control.
    Public Class MyOption1
        Private _id As String
        Private _value As String
        Private _text As String


        Public Property optionid() As
 String
            Get
                Return _id
            End Get
            Set(ByVal value As
 String)
                _id = value
            End Set
        End Property

        Public Property value() As
 String
            Get
                Return _value
            End Get
            Set(ByVal value As
 String)
                _value = value
            End Set
        End Property

        Public Property [text]() As
 String
            Get
                Return _text
            End Get
            Set(ByVal value As
 String)
                _text = value
            End Set
        End Property
    End Class 

    ' Define a type of child control for the custom HtmlSelect control.
    Public Class MyOption2
        Private _id As String
        Private _value As String
        Private _text As String


        Public Property optionid() As
 String
            Get
                Return _id
            End Get
            Set(ByVal value As
 String)
                _id = value
            End Set
        End Property

        Public Property value() As
 String
            Get
                Return _value
            End Get
            Set(ByVal value As
 String)
                _value = value
            End Set
        End Property

        Public Property [text]() As
 String
            Get
                Return _text
            End Get
            Set(ByVal value As
 String)
                _text = value
            End Set
        End Property
    End Class 

    ' Define a custom HtmlSelectBuilder control.
    Public Class MyHtmlSelectBuilder
        Inherits HtmlSelectBuilder

        <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)>
 _
        Public Overrides Function
 GetChildControlType(ByVal tagName As String,
 ByVal attribs As IDictionary) As Type

            ' Distinguish between two possible types of child controls.
            If tagName.ToLower().EndsWith("myoption1")
 Then
                Return GetType(MyOption1)
            ElseIf tagName.ToLower().EndsWith("myoption2")
 Then
                Return GetType(MyOption2)
            End If
            Return Nothing

        End Function 
    End Class 

    <ControlBuilderAttribute(GetType(MyHtmlSelectBuilder))>
 _
    Public Class CustomHtmlSelect
        Inherits HtmlSelect

        ' Override AddParsedSubObject to treat the two types
        ' of child controls differently.
        Protected Overrides Sub
 AddParsedSubObject(ByVal obj As Object)
            Dim _outputtext As String
            If TypeOf obj Is
 MyOption1 Then
                _outputtext = "option group 1: " +
 CType(obj, MyOption1).text
                Dim li As New
 ListItem(_outputtext, CType(obj, MyOption1).value)
                MyBase.Items.Add(li)
            End If
            If TypeOf obj Is
 MyOption2 Then
                _outputtext = "option group 2: " +
 CType(obj, MyOption2).text
                Dim li As New
 ListItem(_outputtext, CType(obj, MyOption2).value)
                MyBase.Items.Add(li)
            End If

        End Sub 
    End Class 
End Namespace
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);
            }
        }
      
    }

}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.ControlBuilder
    System.Web.UI.HtmlControls.HtmlSelectBuilder
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
HtmlSelectBuilder メンバ
System.Web.UI.HtmlControls 名前空間
HtmlSelect クラス
ControlBuilder



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「HtmlSelectBuilder クラス」の関連用語

HtmlSelectBuilder クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HtmlSelectBuilder クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS