DataGrid.CreateControlStyle-Methode
Erstellt einen neuen Steuerelementstil.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Syntax
'Declaration
Protected Overrides Function CreateControlStyle As Style
'Usage
Dim returnValue As Style
returnValue = Me.CreateControlStyle
protected override Style CreateControlStyle ()
protected:
virtual Style^ CreateControlStyle () override
protected Style CreateControlStyle ()
protected override function CreateControlStyle () : Style
Rückgabewert
Style zur Darstellung des neuen Stils.
Beispiel
Das folgende Codebeispiel veranschaulicht das Überschreiben der CreateControlStyle-Methode in einem benutzerdefinierten Serversteuerelement, sodass in DataGrid immer GridLines ohne CellSpacing angezeigt wird.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page language="VB" %>
<HTML>
<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" href="https://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
<%@ Page language="c#" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<HTML>
<HEAD>
<title>Custom DataGrid - CreateControlStyle - C# 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" href="https://www.microsoft.com" />
</Columns>
</aspSample:CustomDataGridCreateControlStyle>
</form>
</body>
</HTML>
...
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomDataGridCreateControlStyle : System.Web.UI.WebControls.DataGrid
{
protected override System.Web.UI.WebControls.Style CreateControlStyle()
{
// Create a new TableStyle instance based on ViewState values.
System.Web.UI.WebControls.TableStyle style = 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;
}
}
}
<%@ Page language="VJ#" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<HTML>
<HEAD>
<title>Custom DataGrid - CreateControlStyle - VJ# Example</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom DataGrid - CreateControlStyle - VJ# Example</h3>
<aspSample:CustomDataGridCreateControlStyle id="Datagrid1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:HyperLinkColumn Text="www.microsoft.com" Target="_blank" HeaderText="HyperLinks" href="https://www.microsoft.com" />
</Columns>
</aspSample:CustomDataGridCreateControlStyle>
</form>
</body>
</HTML>
...
package Samples.AspNet.JSL.Controls;
public class CustomDataGridCreateControlStyle
extends System.Web.UI.WebControls.DataGrid
{
protected System.Web.UI.WebControls.Style CreateControlStyle()
{
// Create a new TableStyle instance based on ViewState values.
System.Web.UI.WebControls.TableStyle style =
new System.Web.UI.WebControls.TableStyle(get_ViewState());
// Show the GridLines with no CellSpacing.
style.set_GridLines(System.Web.UI.WebControls.GridLines.Both);
style.set_CellSpacing(0);
// Return the Style
return style;
} //CreateControlStyle
} //CustomDataGridCreateControlStyle
Plattformen
Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
DataGrid-Klasse
DataGrid-Member
System.Web.UI.WebControls-Namespace
Style