HtmlTable.HtmlTableRowControlCollection.Add(Control) Metoda

Definice

Přidá zadaný Control objekt do kolekce.

public:
 override void Add(System::Web::UI::Control ^ child);
public override void Add (System.Web.UI.Control child);
override this.Add : System.Web.UI.Control -> unit
Public Overrides Sub Add (child As Control)

Parametry

child
Control

Přidání Control do kolekce

Výjimky

Přidaný ovládací prvek musí být typu HtmlTableRow.

Příklady

Následující příklad kódu ukazuje, jak vytvořit vlastní HtmlTable.HtmlTableRowControlCollection kolekci, která přepíše metodu Add tak, aby při přidání řádků do tabulky byly vždy přidány na začátek kolekce řádků tabulky. Všimněte si, jak vlastní Add metoda volá metodu základní třídy AddAt s parametrem index rovnou 0.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>Custom HtmlTable - CustomHtmlTableRowControlCollection Example</title>
  </head>
  <body>
    <form id="Form1" 
          method="post" 
          runat="server">
      <h3>Custom HtmlTable - CustomHtmlTableRowControlCollection Example</h3>
      
      <aspSample:CustomHtmlTableRowControlCollection 
        id="HtmlTable1" 
        name="HtmlTable1" 
        runat="server" 
        border="1"
        cellSpacing="0" 
        cellPadding="5">
        <tr>
          <td>1,1</td>
          <td>1,2</td>
          <td>1,3</td>
        </tr>
        <tr>
          <td>2,1</td>
          <td>2,2</td>
          <td>2,3</td>
        </tr>
        <tr>
          <td>3,1</td>
          <td>3,2</td>
          <td>3,3</td>
        </tr>
      </aspSample:CustomHtmlTableRowControlCollection>

    </form>

  </body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>Custom HtmlTable - CustomHtmlTableRowControlCollection Example</title>
  </head>
  <body>
    <form id="Form1" 
          method="post" 
          runat="server">
      <h3>Custom HtmlTable - CustomHtmlTableRowControlCollection Example</h3>
      
      <aspSample:CustomHtmlTableRowControlCollection 
        id="HtmlTable1" 
        name="HtmlTable1" 
        runat="server" 
        border="1"
        cellSpacing="0" 
        cellPadding="5">
        <tr>
          <td>1,1</td>
          <td>1,2</td>
          <td>1,3</td>
        </tr>
        <tr>
          <td>2,1</td>
          <td>2,2</td>
          <td>2,3</td>
        </tr>
        <tr>
          <td>3,1</td>
          <td>3,2</td>
          <td>3,3</td>
        </tr>
      </aspSample:CustomHtmlTableRowControlCollection>

    </form>

  </body>
</html>
using System.Web;
using System.Web.UI;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
    [AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
    public class CustomHtmlTableRowControlCollection : System.Web.UI.HtmlControls.HtmlTable
    {

       protected override ControlCollection CreateControlCollection()
       {

         return new MyHtmlTableRowControlCollection(this);
       }

       protected class MyHtmlTableRowControlCollection : ControlCollection
       {

         internal MyHtmlTableRowControlCollection(Control owner) : base(owner) { }

         public override void Add(Control child)
         {

           // Always add new rows at the top of the table.
           base.AddAt(0, child);
         }
       }
    }
}
Imports System.Web
Imports System.Web.UI
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomHtmlTableRowControlCollection
        Inherits System.Web.UI.HtmlControls.HtmlTable

        Protected Overrides Function CreateControlCollection() As System.Web.UI.ControlCollection

            Return New MyHtmlTableRowControlCollection(Me)

        End Function

        Protected Class MyHtmlTableRowControlCollection
            Inherits ControlCollection

            Friend Sub New(ByVal owner As Control)

                MyBase.New(owner)

            End Sub

            Public Overrides Sub Add(ByVal child As Control)

                ' Always add new rows at the top of the table.
                MyBase.AddAt(0, child)

            End Sub

        End Class

    End Class

End Namespace

Poznámky

Přidaný HtmlTableRow ovládací prvek může být pouze ovládací prvek, ArgumentException jinak se vyvolá výjimka.

Platí pro

Viz také