DataList.CreateControlStyle 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DataList 컨트롤에서 모든 스타일 관련 속성을 구현하기 위해 내부적으로 사용되는 기본 스타일 개체를 만듭니다.
protected:
override System::Web::UI::WebControls::Style ^ CreateControlStyle();
protected override System.Web.UI.WebControls.Style CreateControlStyle ();
override this.CreateControlStyle : unit -> System.Web.UI.WebControls.Style
Protected Overrides Function CreateControlStyle () As Style
반환
컨트롤에 대한 기본 스타일 속성이 들어 있는 TableStyle입니다.
예제
다음 코드 예제에서는 컨트롤에 셀 간격이 없는 가로 눈금선을 항상 표시하도록 사용자 지정 서버 컨트롤에서 메서드를 재정 CreateControlStyle 의 DataList 하는 방법을 보여 줍니다.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!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 DataList - CreateControlStyle - C# 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.Columns.Add(new System.Data.DataColumn("Column1", typeof(String)));
dr = dt.NewRow();
dr[0] = "Hello";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "DataList";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = "World";
dt.Rows.Add(dr);
// Show the DataTable values in the DataList.
DataList1.DataSource = dt;
DataList1.DataBind();
}
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom DataList - CreateControlStyle - C# 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.DataItem, "Column1") %></asp:Label>
</ItemTemplate>
<AlternatingItemStyle BackColor="#DCDCDC" />
<AlternatingItemTemplate>
<asp:Label id="Label3" runat="server"><%# DataBinder.Eval(Container.DataItem, "Column1") %></asp:Label>
</AlternatingItemTemplate>
</aspSample:CustomDataListCreateControlStyle>
</form>
</body>
</html>
<%@ 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 DataList - CreateControlStyle - VB Example</title>
<script runat="server">
Private Sub Page_Load(sender As Object, e As EventArgs)
' Create sample data for the DataList control.
Dim dt As System.Data.DataTable = New System.Data.DataTable()
Dim dr As System.Data.DataRow
' Create a new column named Column1, of type String.
Dim col As New System.Data.DataColumn("Column1", GetType(String))
' Add the column to the DataTable.
dt.Columns.Add(col)
dr = dt.NewRow()
dr(0) = "Hello"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "DataList"
dt.Rows.Add(dr)
dr = dt.NewRow()
dr(0) = "World"
dt.Rows.Add(dr)
' Show the DataTable values in the DataList.
DataList1.DataSource = dt
DataList1.DataBind()
End Sub ' Page_Load
</script>
</head>
<body>
<form id="Form1" method="post" runat="server">
<h3>Custom DataList - CreateControlStyle - VB 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.DataItem, "Column1") %></asp:Label>
</ItemTemplate>
<AlternatingItemStyle BackColor="#DCDCDC" />
<AlternatingItemTemplate>
<asp:Label id="Label3" runat="server"><%# DataBinder.Eval(Container.DataItem, "Column1") %></asp:Label>
</AlternatingItemTemplate>
</aspSample:CustomDataListCreateControlStyle>
</form>
</body>
</html>
using System.Web;
using System.Security.Permissions;
namespace Samples.AspNet.CS.Controls
{
[AspNetHostingPermission(SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class CustomDataListCreateControlStyle : System.Web.UI.WebControls.DataList
{
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 horizontal with no CellSpacing.
style.GridLines = System.Web.UI.WebControls.GridLines.Horizontal;
style.CellSpacing = 0;
// Return the Style
return style;
}
}
}
Imports System.Web
Imports System.Security.Permissions
Namespace Samples.AspNet.VB.Controls
<AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class CustomDataListCreateControlStyle
Inherits System.Web.UI.WebControls.DataList
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 horizontal with no CellSpacing.
style.GridLines = System.Web.UI.WebControls.GridLines.Horizontal
style.CellSpacing = 0
' Return the Style
Return style
End Function
End Class
End Namespace
설명
이 CreateControlStyle 메서드는 주로 컨트롤 개발자가 컨트롤에서 DataList 사용자 지정 구현을 파생시키는 데 사용됩니다.