DataGrid.CreateControlStyle Method
.NET Framework 3.0
Creates new control style.
Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)
Assembly: System.Web (in system.web.dll)
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.
<%@ Page language="VJ#" %>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<!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 - 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" NavigateUrl="http://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
Community Additions
ADD
Show: