DataGrid.CreateControlStyle Method ()

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates new control style.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

Protected Overrides Function CreateControlStyle As Style

Return Value

Type: System.Web.UI.WebControls.Style

A Style the represents the new style.

The following code example demonstrates how to override the CreateControlStyle method in a custom server control so that it always displays the GridLines with no CellSpacing in the DataGrid.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<!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" >
  <head>
    <title>Custom DataGrid - CreateControlStyle - VB.NET Example</title>
  </head>
  <body>
    <form id="Form1" method="post" runat="server">
      <h3>Custom DataGrid - CreateControlStyle - C# Example</h3>
            <aspSample:CustomDataGridCreateControlStyle id="Datagrid1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:HyperLinkColumn Text="www.microsoft.com" Target="_blank" HeaderText="HyperLinks" NavigateUrl="http://www.microsoft.com" />
                </Columns>
            </aspSample:CustomDataGridCreateControlStyle>
    </form>
  </body>
</html>
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomDataGridCreateControlStyle
        Inherits System.Web.UI.WebControls.DataGrid

        Protected Overrides Function CreateControlStyle() As System.Web.UI.WebControls.Style

            ' Create a new TableStyle instance based on ViewState values.
            Dim style As New System.Web.UI.WebControls.TableStyle(ViewState)

            ' Show the GridLines with no CellSpacing.
            style.GridLines = System.Web.UI.WebControls.GridLines.Both
            style.CellSpacing = 0

            ' Return the Style
            Return style
        End Function
    End Class
End Namespace

.NET Framework
Available since 1.1
Return to top
Show: