共用方式為


Style Properties 

Some controls support style properties that allow you to set the appearance, such as color and font, of individual elements within the control. To change the appearance of an element, set the properties for the appropriate style object.

<asp:control id="value" runat="server"> 
  
   <StyleObject property1="value"  
                property2="value"/> 
  
</asp:control>

Remarks

All style classes derive from the Style class and support the properties defined in the base class. Style classes also implement additional properties specific to the class.

When declaring a Web server control, specify the properties for a particular style object by nesting the element that represents the object (such as <SelectedDayStyle>) between the opening and closing tags of the control. You can then list the individual style properties (such as BackColor="Blue") within the element.

For more information about these properties, see the System.Web.UI.WebControls.Style class and its derived classes.

Example

To set the appearance of the selected day in a Calendar Web server control, set the style properties of the SelectedDayStyle tag. The following code example demonstrates how to specify a blue background, red text, and Arial font for the selected date in the control. Notice that the Font property belongs to the Calendar control and not the TableItemStyle object.

<asp:Calendar id="Calendar1"
     Font-Name="Arial" 
     runat="server">

   <SelectedDayStyle BackColor="Blue" 
                     ForeColor="Red"/>

</asp:Calendar>

See Also

Reference

Style

Other Resources

Web Server Control Syntax