Duration (Pacific Standard Time):
To (Pacific Standard Time):
Impact:
User Action:
.NET Framework Class Library

WebControl.MergeStyle Method

Copies any nonblank elements of the specified style to the Web control, but will not overwrite any existing style elements of the control. This method is used primarily by control developers.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Public Sub MergeStyle ( _
	s As Style _
)

Parameters

s
Type: System.Web.UI.WebControls.Style

A Style that represents the style to be copied.

The following example demonstrates how to use the MergeStyle method to merge a style with the style of a DataGrid control.

Note Note

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Forms Page Code Model.


<%@ Page Language="VB" AutoEventWireup="True" %>

<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
   <script runat="server">

      Private Function CreateDataSource() As ICollection 

         Dim dt As DataTable = New DataTable
         Dim dr As DataRow
         Dim dv As DataView
         Dim i As Integer

         dt.Columns.Add(New DataColumn("IntegerValue", GetType(Integer)))
         dt.Columns.Add(New DataColumn("StringValue", GetType(String)))
         dt.Columns.Add(New DataColumn("CurrencyValue", GetType(Double)))

         for i = 0 to 9  

            dr = dt.NewRow()

            dr(0) = i
            dr(1) = "Item " + i.ToString()
            dr(2) = 1.23 * (i + 1)

            dt.Rows.Add(dr)

         next i

         dv = New DataView(dt)
         CreateDataSource = dv

      End Function

      Private Sub Page_Load(sender As Object, e As EventArgs) 

         If Not IsPostBack Then 
            ' Load this data only once.
            ItemsGrid.DataSource = CreateDataSource()
            ItemsGrid.DataBind()
         End If

      End Sub

      Private Sub Button_Click(sender As Object, e As EventArgs) 

         Dim myStyle As Style = new Style()
         myStyle.ForeColor = System.Drawing.Color.Red

         ItemsGrid.MergeStyle(myStyle)

      End Sub

   </script>

<head runat="server">
    <title>WebControl MergeStyle Example</title>
</head>
<body>

   <form id="form1" runat="server">

      <h3>WebControl MergeStyle Example</h3>

      <b>Product List</b>

      <asp:DataGrid id="ItemsGrid"
           BorderColor="black"
           BorderWidth="1"
           BackColor="Yellow"
           CellPadding="3"
           AutoGenerateColumns="false"
           runat="server">

         <HeaderStyle BackColor="#00aaaa">
         </HeaderStyle>

         <Columns>

            <asp:BoundColumn
                 HeaderText="Number" 
                 DataField="IntegerValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Description" 
                 DataField="StringValue">
            </asp:BoundColumn>

            <asp:BoundColumn
                 HeaderText="Price" 
                 DataField="CurrencyValue" 
                 DataFormatString="{0:c}">
            </asp:BoundColumn>

         </Columns>

      </asp:DataGrid>

      <br /><br />

      <asp:Button id="Button1" 
           Text="Merge Custom Style"
           OnClick="Button_Click"
           runat="server"/>

   </form>

</body>
</html>

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.