CssStyleCollection.Item[] Właściwość

Definicja

Pobiera lub ustawia wartość CSS dla kontrolki serwera HTML.

Przeciążenia

Item[String]

Pobiera lub ustawia określoną wartość CSS dla kontrolki serwera HTML.

Item[HtmlTextWriterStyle]

Pobiera lub ustawia określoną HtmlTextWriterStyle wartość dla kontrolki serwera HTML.

Item[String]

Pobiera lub ustawia określoną wartość CSS dla kontrolki serwera 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

Parametry

key
String

Indeks atrybutu CSS.

Wartość właściwości

Wartość .key

Przykłady

W poniższym przykładzie kodu użyto Item[] właściwości , aby zwrócić wartość stylu ustawionego na kontrolce HtmlInputText .

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

Zobacz też

Dotyczy

Item[HtmlTextWriterStyle]

Pobiera lub ustawia określoną HtmlTextWriterStyle wartość dla kontrolki serwera 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

Parametry

Wartość właściwości

Wartość key; w przeciwnym razie , nulljeśli key nie znajduje się w kolekcji kontrolki serwera.

Przykłady

W poniższym przykładzie kodu użyto Item[] właściwości , aby zwrócić wartość stylu ustawionego na kontrolce HtmlInputText .

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

Uwagi

Elementy stylu dodawane programowo do CssStyleCollection kolekcji dla kontrolki z Item[] właściwością lub Add metodą, która pobiera HtmlTextWriterStyle wartość wyliczenia jako dane wejściowe, są uwzględniane w liczbie elementów stylu zwracanych z Count właściwością i są dołączane do literału ciągu zwracanego z właściwością Value . Te atrybuty są silnie typizowane. Jeśli atrybut kaskadowego arkusza stylów, który chcesz dodać do kontrolki serwera, istnieje w wyliczenie HtmlTextWriterStyle , użyj tych silnie typiowanych metod. Jeśli atrybut, który chcesz dodać, nie istnieje w wyliczenie HtmlTextWriterStyle , użyj Item[] właściwości lub Add metody .

Próba uzyskania dostępu HtmlTextWriterStyle do wartości wyliczenia w CssStyleCollection kontrolce, która nie została dodana lub aby uzyskać dostęp do atrybutu CSS, który został dodany z Item[] właściwością lub Add metodą, zwraca null wartość przy użyciu Item[] właściwości .

Zobacz też

Dotyczy