CssStyleCollection.Item[] Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Recebe ou define um valor CSS para o controlo do servidor HTML.
Sobrecargas
| Name | Description |
|---|---|
| Item[String] |
Obtém ou define o valor CSS especificado para o controlo do servidor HTML. |
| Item[HtmlTextWriterStyle] |
Obtém ou define o valor especificado HtmlTextWriterStyle para o controlo do servidor HTML. |
Item[String]
Obtém ou define o valor CSS especificado para o controlo do servidor 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
Parâmetros
- key
- String
O índice do atributo CSS.
Valor de Propriedade
O valor de key.
Exemplos
O exemplo de código seguinte usa a Item[] propriedade para devolver o valor de um estilo que está definido num HtmlInputText controlo.
<%@ 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>
Ver também
Aplica-se a
Item[HtmlTextWriterStyle]
Obtém ou define o valor especificado HtmlTextWriterStyle para o controlo do servidor 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
Parâmetros
Valor de Propriedade
O valor key; caso contrário, null, se key não estiver na coleção do controlo do servidor.
Exemplos
O exemplo de código seguinte usa a Item[] propriedade para devolver o valor de um estilo que está definido num HtmlInputText controlo.
<%@ 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>
Observações
Itens de estilo que são adicionados programaticamente a uma CssStyleCollection coleção para um controlo com a Item[] propriedade ou o Add método que recebem um HtmlTextWriterStyle valor de enumeração como entrada são incluídos na contagem de itens de estilo que são devolvidos com a Count propriedade e são incluídos com o literal da cadeia que é devolvido com a Value propriedade. Estes atributos são fortemente tipados. Se o atributo da folha de estilo em cascata que pretende adicionar a um controlo de servidor existir na HtmlTextWriterStyle enumeração, use estes métodos fortemente tipados. Se o atributo que pretende adicionar não existir na HtmlTextWriterStyle enumeração, use a Item[] propriedade ou o Add método.
Tentar aceder a um HtmlTextWriterStyle valor de enumeração num CssStyleCollection controlo que não foi adicionado ou aceder a um atributo CSS que foi adicionado com a Item[] propriedade ou o Add método, retorna null usando essa Item[] propriedade.