CssStyleCollection.Item[] Proprietà

Definizione

Ottiene o imposta un valore CSS per il controllo server HTML.

Overload

Item[String]

Ottiene o imposta il valore CSS specificato per il controllo server HTML.

Item[HtmlTextWriterStyle]

Ottiene o imposta il valore HtmlTextWriterStyle specificato per il controllo server HTML.

Item[String]

Ottiene o imposta il valore CSS specificato per il controllo server 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

Parametri

key
String

Indice per l'attributo CSS.

Valore della proprietà

Valore di key.

Esempio

Nell'esempio di codice seguente viene utilizzata la Item[] proprietà per restituire il valore di uno stile impostato su un HtmlInputText controllo .

<%@ 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>

Vedi anche

Si applica a

Item[HtmlTextWriterStyle]

Ottiene o imposta il valore HtmlTextWriterStyle specificato per il controllo server 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

Parametri

Valore della proprietà

Valore key; in caso contrario, null, se key non è incluso nell'insieme del controllo server.

Esempio

Nell'esempio di codice seguente viene utilizzata la Item[] proprietà per restituire il valore di uno stile impostato su un HtmlInputText controllo .

<%@ 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>

Commenti

Gli elementi di stile aggiunti a livello di codice a un insieme per un CssStyleCollection controllo con la Item[] proprietà o il Add metodo che accettano un HtmlTextWriterStyle valore di enumerazione come input vengono inclusi nel conteggio degli elementi di stile restituiti con la Count proprietà e inclusi nel valore letterale stringa restituito con la Value proprietà . Questi attributi sono fortemente tipizzato. Se l'attributo del foglio di stile a catena che si desidera aggiungere a un controllo server esiste nell'enumerazione HtmlTextWriterStyle , utilizzare questi metodi fortemente tipizzato. Se l'attributo da aggiungere non esiste nell'enumerazione HtmlTextWriterStyle , utilizzare la Item[] proprietà o il Add metodo .

Se si tenta di accedere a un HtmlTextWriterStyle valore di enumerazione in CssStyleCollection di un controllo che non è stato aggiunto o di accedere a un attributo CSS aggiunto con la Item[] proprietà o il Add metodo , restituisce null utilizzando la Item[] proprietà .

Vedi anche

Si applica a