CssStyleCollection.Value 属性

定义

获取或设置 HTML 服务器控件的 style 特性的值。

public:
 property System::String ^ Value { System::String ^ get(); void set(System::String ^ value); };
public string Value { get; set; }
member this.Value : string with get, set
Public Property Value As String

属性值

String

样式字符串。

示例

下面的代码示例演示如何在用户单击提交按钮时使用 Value 属性列出控件的 HtmlSelect 样式属性。

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

适用于

另请参阅