DataList.CreateControlStyle Method
.NET Framework 2.0
Creates the default style object that is used internally by the DataList control to implement all style related properties.
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 horizontal grid lines with no cell spacing in the DataList control.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL.Controls" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<HTML>
<HEAD>
<title>Custom DataList - CreateControlStyle - VJ# Example</title>
<script runat="server">
private void Page_Load(Object sender, System.EventArgs e)
{
// Create sample data for the DataList control.
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.get_Columns().Add(new System.Data.DataColumn("Column1",
String.class.ToType()));
dr = dt.NewRow();
dr.set_Item(0, "Hello");
dt.get_Rows().Add(dr);
dr = dt.NewRow();
dr.set_Item(0, "DataList");
dt.get_Rows().Add(dr);
dr = dt.NewRow();
dr.set_Item(0, "World");
dt.get_Rows().Add(dr);
// Show the DataTable values in the DataList.
DataList1.set_DataSource(dt);
DataList1.DataBind();
} //Page_Load
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom DataList - CreateControlStyle - VJ# Example</h3>
<aspSample:CustomDataListCreateControlStyle id="DataList1" runat="server" BorderColor="#999999" BorderStyle="None" BackColor="White" CellPadding="3" GridLines="Vertical" BorderWidth="1px" Width="100px">
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#000084" />
<HeaderTemplate>
<asp:Label id="Label1" runat="server">Column1</asp:Label>
</HeaderTemplate>
<ItemStyle ForeColor="Black" BackColor="#EEEEEE" />
<ItemTemplate>
<asp:Label id="Label2" runat="server"><%# DataBinder.Eval(Container.get_DataItem(), "Column1") %></asp:Label>
</ItemTemplate>
<AlternatingItemStyle BackColor="#DCDCDC" />
<AlternatingItemTemplate>
<asp:Label id="Label3" runat="server"><%# DataBinder.Eval(Container.get_DataItem(), "Column1") %></asp:Label>
</AlternatingItemTemplate>
</aspSample:CustomDataListCreateControlStyle>
</form>
</body>
</HTML>
...package Samples.AspNet.JSL.Controls;
public class CustomDataListCreateControlStyle
extends System.Web.UI.WebControls.DataList
{
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 horizontal with no CellSpacing.
style.set_GridLines(System.Web.UI.WebControls.GridLines.Horizontal);
style.set_CellSpacing(0);
// Return the Style
return style;
} //CreateControlStyle
} //CustomDataListCreateControlStyle
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
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: