CssStyleCollection.Add Método

Definição

Adiciona um item de estilo ao CssStyleCollection de um controle.Adds a style item to the CssStyleCollection of a control.

Sobrecargas

Add(String, String)

Adiciona um item de estilo do CssStyleCollection de um controle usando o par nome/valor especificado.Adds a style item to the CssStyleCollection of a control using the specified name/value pair.

Add(HtmlTextWriterStyle, String)

Adiciona um item de estilo à coleção CssStyleCollection de um controle usando o valor de enumeração HtmlTextWriterStyle especificado e o valor correspondente.Adds a style item to the CssStyleCollection collection of a control using the specified HtmlTextWriterStyle enumeration value and corresponding value.

Add(String, String)

Adiciona um item de estilo do CssStyleCollection de um controle usando o par nome/valor especificado.Adds a style item to the CssStyleCollection of a control using the specified name/value pair.

public:
 void Add(System::String ^ key, System::String ^ value);
public void Add (string key, string value);
member this.Add : string * string -> unit
Public Sub Add (key As String, value As String)

Parâmetros

key
String

O nome do novo atributo de estilo a ser adicionado à coleção.The name of the new style attribute to add to the collection.

value
String

O valor do atributo de estilo a ser adicionado à coleção.The value of the style attribute to add to the collection.

Exceções

key é null.key is null.

Exemplos

O exemplo de código a seguir demonstra como usar as sobrecargas do Add método para adicionar uma folha de estilos em cascata a um HtmlSelect , HtmlInputSubmit e um Label controle programaticamente.The following code example demonstrates how to use both overloads of the Add method to add a cascading style sheet to an HtmlSelect, HtmlInputSubmit, and a Label control programmatically.

<%@ Page Language="C#" %>

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

<script runat="server">

  protected void SubmitBtn_Click(object sender, EventArgs e)
  {
    SubmitBtn.Style.Add("letter-spacing", "10px");
    FirstSelect.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items[FirstSelect.SelectedIndex].Value.ToString());
    Message.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items[FirstSelect.SelectedIndex].Value.ToString());
    Message.Text = "The select style is: " + FirstSelect.Style.Value;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssStyleCollection Add</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Select a color and then click submit.
    <br />
    <select id="FirstSelect" 
            style="font: 10pt verdana;color:black;" 
            runat="server">
        <option value="black">black</option>
        <option value="red">red</option>
        <option value="blue">blue</option>
        <option value="green">green</option>
    </select> 
    <input id="SubmitBtn" 
           value="Submit" 
           type="submit" 
           onserverclick="SubmitBtn_Click"
           runat="server" /><br/>
    <br />
    <asp:Label id="Message"
               runat="server"/>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

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

<script runat="server">

  Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    
    SubmitBtn.Style.Add("letter-spacing", "10px")
    FirstSelect.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items(FirstSelect.SelectedIndex).Value.ToString())
    Message.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items(FirstSelect.SelectedIndex).Value.ToString())
    Message.Text = "The select style is: " + FirstSelect.Style.Value

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssStyleCollection Add</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Select a color and then click submit.
    <br />
    <select id="FirstSelect" 
            style="font: 10pt verdana;color:black;" 
            runat="server">
        <option value="black">black</option>
        <option value="red">red</option>
        <option value="blue">blue</option>
        <option value="green">green</option>
    </select> 
    <input id="SubmitBtn" 
           value="Submit" 
           type="submit" 
           onserverclick="SubmitBtn_Click"
           runat="server" /><br />
    <br />
    <asp:Label id="Message"
               runat="server"/>
    </div>
    </form>
</body>
</html>

Comentários

Se o item de estilo a ser adicionado existir na HtmlTextWriterStyle enumeração, use a sobrecarga do Add método que usa um HtmlTextWriterStyle parâmetro porque ele é fortemente tipado.If the style item to add exists in the HtmlTextWriterStyle enumeration, use the overload of the Add method that takes an HtmlTextWriterStyle parameter because it is strongly typed. Isso significa que os itens adicionados serão incluídos durante a exibição de itens com o acessador get da Item[] propriedade.This means that items that are added will be included when viewing items with the get accessor of the Item[] property.

Confira também

Aplica-se a

Add(HtmlTextWriterStyle, String)

Adiciona um item de estilo à coleção CssStyleCollection de um controle usando o valor de enumeração HtmlTextWriterStyle especificado e o valor correspondente.Adds a style item to the CssStyleCollection collection of a control using the specified HtmlTextWriterStyle enumeration value and corresponding value.

public:
 void Add(System::Web::UI::HtmlTextWriterStyle key, System::String ^ value);
public void Add (System.Web.UI.HtmlTextWriterStyle key, string value);
member this.Add : System.Web.UI.HtmlTextWriterStyle * string -> unit
Public Sub Add (key As HtmlTextWriterStyle, value As String)

Parâmetros

key
HtmlTextWriterStyle

O valor de enumeração HtmlTextWriterStyle a ser adicionado à coleção.The HtmlTextWriterStyle enumeration value to add to the collection.

value
String

O valor do atributo de estilo a ser adicionado à coleção.The value of the style attribute to add to the collection.

Exemplos

O exemplo de código a seguir demonstra como usar as sobrecargas do Add método para adicionar uma folha de estilos em cascata a um HtmlSelect , HtmlInputSubmit e um Label controle programaticamente.The following code example demonstrates how to use both overloads of the Add method to add a cascading style sheet to an HtmlSelect, HtmlInputSubmit, and a Label control programmatically.

<%@ Page Language="C#" %>

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

<script runat="server">

  protected void SubmitBtn_Click(object sender, EventArgs e)
  {
    SubmitBtn.Style.Add("letter-spacing", "10px");
    FirstSelect.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items[FirstSelect.SelectedIndex].Value.ToString());
    Message.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items[FirstSelect.SelectedIndex].Value.ToString());
    Message.Text = "The select style is: " + FirstSelect.Style.Value;
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssStyleCollection Add</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Select a color and then click submit.
    <br />
    <select id="FirstSelect" 
            style="font: 10pt verdana;color:black;" 
            runat="server">
        <option value="black">black</option>
        <option value="red">red</option>
        <option value="blue">blue</option>
        <option value="green">green</option>
    </select> 
    <input id="SubmitBtn" 
           value="Submit" 
           type="submit" 
           onserverclick="SubmitBtn_Click"
           runat="server" /><br/>
    <br />
    <asp:Label id="Message"
               runat="server"/>
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

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

<script runat="server">

  Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    
    SubmitBtn.Style.Add("letter-spacing", "10px")
    FirstSelect.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items(FirstSelect.SelectedIndex).Value.ToString())
    Message.Style.Add(HtmlTextWriterStyle.Color, FirstSelect.Items(FirstSelect.SelectedIndex).Value.ToString())
    Message.Text = "The select style is: " + FirstSelect.Style.Value

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssStyleCollection Add</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Select a color and then click submit.
    <br />
    <select id="FirstSelect" 
            style="font: 10pt verdana;color:black;" 
            runat="server">
        <option value="black">black</option>
        <option value="red">red</option>
        <option value="blue">blue</option>
        <option value="green">green</option>
    </select> 
    <input id="SubmitBtn" 
           value="Submit" 
           type="submit" 
           onserverclick="SubmitBtn_Click"
           runat="server" /><br />
    <br />
    <asp:Label id="Message"
               runat="server"/>
    </div>
    </form>
</body>
</html>

Comentários

Se o item de estilo a ser adicionado existir na HtmlTextWriterStyle enumeração, use essa Add sobrecarga do Add método em vez da sobrecarga que não usa um HtmlTextWriterStyle parâmetro.If the style item to add exists in the HtmlTextWriterStyle enumeration, use this Add overload of the Add method rather than the overload that does not take an HtmlTextWriterStyle parameter.

Confira também

Aplica-se a