CssStyleCollection.Item[] Propriété

Définition

Obtient ou définit une valeur CSS pour le contrôle serveur HTML.

Surcharges

Item[String]

Obtient ou définit la valeur CSS spécifiée pour le contrôle serveur HTML.

Item[HtmlTextWriterStyle]

Obtient ou définit la valeur HtmlTextWriterStyle pour le contrôle serveur HTML.

Item[String]

Obtient ou définit la valeur CSS spécifiée pour le contrôle serveur HTML.

public:
 property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ key); void set(System::String ^ key, System::String ^ value); };
public string this[string key] { get; set; }
member this.Item(string) : string with get, set
Default Public Property Item(key As String) As String

Paramètres

key
String

Index de l'attribut CSS.

Valeur de propriété

String

la valeur de la propriété key ;

Exemples

L’exemple de code suivant utilise la Item[] propriété pour renvoyer la valeur d’un style défini sur un HtmlInputText contrôle.

<%@ 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 Page_Load(object sender, EventArgs e)
  {
    MyText.Style.Add(HtmlTextWriterStyle.Width, "200");
    FirstMessage.Text = "The text box font color is: " + 
      MyText.Style["color"] + "<br />" +
      "The text box width is: " + 
      MyText.Style[HtmlTextWriterStyle.Width];
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssCollection This Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <input id="MyText"
             type="text" 
             value="Type a value here."
             style="font: 14pt Verdana; color: blue;"
             runat="server"/>
      <br />
      <asp:Label id="FirstMessage"
                 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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    MyText.Style.Add(HtmlTextWriterStyle.Width, "200")
    FirstMessage.Text = "The text box font color is: " _
      & MyText.Style("color") & "<br />" _
      & "The text box width is: " & MyText.Style(HtmlTextWriterStyle.Width)

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssCollection This Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <input id="MyText"
             type="text" 
             value="Type a value here."
             style="font: 14pt Verdana; color: blue;"
             runat="server"/>
      <br />
      <asp:Label id="FirstMessage"
                 runat="server"/>
    </div>
    </form>
</body>
</html>

Voir aussi

S’applique à

Item[HtmlTextWriterStyle]

Obtient ou définit la valeur HtmlTextWriterStyle pour le contrôle serveur HTML.

public:
 property System::String ^ default[System::Web::UI::HtmlTextWriterStyle] { System::String ^ get(System::Web::UI::HtmlTextWriterStyle key); void set(System::Web::UI::HtmlTextWriterStyle key, System::String ^ value); };
public string this[System.Web.UI.HtmlTextWriterStyle key] { get; set; }
member this.Item(System.Web.UI.HtmlTextWriterStyle) : string with get, set
Default Public Property Item(key As HtmlTextWriterStyle) As String

Paramètres

Valeur de propriété

String

key de la valeur ; sinon, null, si key ne figure pas dans la collection du contrôle serveur.

Exemples

L’exemple de code suivant utilise la Item[] propriété pour renvoyer la valeur d’un style défini sur un HtmlInputText contrôle.

<%@ 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 Page_Load(object sender, EventArgs e)
  {
    MyText.Style.Add(HtmlTextWriterStyle.Width, "200");
    FirstMessage.Text = "The text box font color is: " + 
      MyText.Style["color"] + "<br />" +
      "The text box width is: " + 
      MyText.Style[HtmlTextWriterStyle.Width];
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssCollection This Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <input id="MyText"
             type="text" 
             value="Type a value here."
             style="font: 14pt Verdana; color: blue;"
             runat="server"/>
      <br />
      <asp:Label id="FirstMessage"
                 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 Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

    MyText.Style.Add(HtmlTextWriterStyle.Width, "200")
    FirstMessage.Text = "The text box font color is: " _
      & MyText.Style("color") & "<br />" _
      & "The text box width is: " & MyText.Style(HtmlTextWriterStyle.Width)

  End Sub
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>CssCollection This Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <input id="MyText"
             type="text" 
             value="Type a value here."
             style="font: 14pt Verdana; color: blue;"
             runat="server"/>
      <br />
      <asp:Label id="FirstMessage"
                 runat="server"/>
    </div>
    </form>
</body>
</html>

Remarques

Les éléments de style ajoutés par programmation à une collection pour un CssStyleCollection contrôle avec la Item[] propriété ou la Add méthode qui acceptent une HtmlTextWriterStyle valeur d’énumération en tant qu’entrée sont inclus dans le nombre d’éléments de style retournés avec la Count propriété et sont inclus avec le littéral de chaîne retourné avec la Value propriété. Ces attributs sont fortement typés. Si l’attribut de feuille de style en cascade que vous souhaitez ajouter à un contrôle de serveur existe dans l’énumération HtmlTextWriterStyle , utilisez ces méthodes fortement typées. Si l’attribut que vous souhaitez ajouter n’existe pas dans l’énumération HtmlTextWriterStyle , utilisez la Item[] propriété ou la Add méthode.

Essayez d’accéder à une HtmlTextWriterStyle valeur d’énumération dans le CssStyleCollection contrôle qui n’a pas été ajouté ou d’accéder à un attribut CSS qui a été ajouté avec la Item[] propriété ou la Add méthode, retourne null à l’aide de la Item[] propriété.

Voir aussi

S’applique à