Style object

xiaoxiao2021-03-06  69

ASP.NET supports style objects (style objects allow users to set some appearances such as color and "Let some controls look more sampled. It uses the syntax:

The following example is simple to set the SelectedDayStyle object of the calendar web control. This object determines the style displayed when the date on the calendar control is selected:

style object is divided into three categories, based on the base style, TableItem style, and DataGridPager style; these styles are used in different places. Setting the Style Properties Web Form Designer in the Web Form Designer provides a convenient tool for easy setting of style properties. Setting the Styled Properties in the Web Form Designer In the Design view, select the control you want to set up. In the Properties window, complete the following: VS.NET 2003 DataGrid style is expanded the style object and then set the properties of the object. For example, to set the properties of the ItemStyle object of the DataList control, expand ItemStyle in the Properties window. - or - If the control supports the property generator (eg, DataList and DataGrid controls), click the Properties Builder at the bottom of the Properties window to open the Properties dialog. Select the "Format" option, select a style object in the Object list and set its properties. Setting Style Properties You can set the style properties directly in two ways in the .aspx file. Directly set the style attribute in the .aspx file Using Style Object Name and Property Connection Declaration Style Properties: - or - Declare the display element in the properties of the appropriate data type: Note If the web form designer cannot correctly present a Web server control correctly, it will display a gray box, which shows the text "Creating a control". " This usually means that the ASP.NET syntax of the control is incorrect, for example, this error will be displayed if the Runat = "Server" property is missing in a web server control element. Point to the information icon (); the tool prompt will be displayed, which contains more information about the error. By programming style properties You can set the style properties of the controls by programming, allowing you to change the appearance of the control.

The following hierarchical agreements are specified by programming styled properties: control.StyleObject.property = value The following example shows how to set the backcolor property of the DayStyle object of the Calendar control: 'Visual Basiccalendar1.dayStyle.backColor = Color .Green // c # Calendar1.dayStyle.backcolor = color.green; You can also create a separate style object and copy its property value or merged into one of the style on the control. This is an effective way to apply the same style to several different list objects in the project. To do this, you can create a virtual style sheet as the Style object and then apply it to a series of controls. Create a style object and apply it to the control instance to create a style object: 'Visual BasicDim S as style = new style () s.backcolor = color.red

// c # style s = new style (); s.backcolor = color.red; assign the Style object to the control using one of the following methods: CopyFrom method Apply all settings from the Style object, including empty settings. The mergewith method only copies the properties that have been set on the Style object, and skip the STYLE attribute that is not set. In addition, the MergeWith method will not override any existing style elements. The following example shows one of the following methods, how to create a style object, set an attribute, and then apply it to two different control style objects: 'Visual Basic' Apply Values ​​In s, includedaystyle .Copyfrom (s) 'Apply Only Values ​​In s That Are Null in Headerstyle.DataGrid1.Headerstyle.Mergewith (s)

// c # // Apply All Values ​​In s, including inclus.calendar1.selectedDayStyle.copyFrom (s); // Apply Only.DataGrid1.Headersty.DataGrid1.Headersty.Mergewith (s);

转载请注明原文地址:https://www.9cbs.com/read-92278.html

New Post(0)