FormView.HeaderRow 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
FormViewRow 컨트롤의 머리글 행을 나타내는 FormView 개체를 가져옵니다.
public:
virtual property System::Web::UI::WebControls::FormViewRow ^ HeaderRow { System::Web::UI::WebControls::FormViewRow ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.FormViewRow HeaderRow { get; }
[<System.ComponentModel.Browsable(false)>]
member this.HeaderRow : System.Web.UI.WebControls.FormViewRow
Public Overridable ReadOnly Property HeaderRow As FormViewRow
속성 값
FormViewRow 컨트롤의 머리글 행을 나타내는 FormView입니다.
- 특성
예제
다음 예제에서는 사용 HeaderRow 하는 방법에 설명 합니다 속성 프로그래밍 방식으로 이벤트 동안 ItemCreated 헤더 행의 속성을 수정 합니다.
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
void EmployeeFormView_ItemCreated(Object sender, EventArgs e)
{
// Use the HeaderRow property to retrieve the header row.
FormViewRow header = EmployeeFormView.HeaderRow;
// Retrieve the HeaderLabel Label control from the header row.
Label headerLabel = (Label)header.FindControl("HeaderLabel");
if(headerLabel != null)
{
// Display the current page number.
int currentPage = EmployeeFormView.PageIndex + 1;
headerLabel.Text = "Page " + currentPage.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView HeaderTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>FormView HeaderTemplate Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
onitemcreated="EmployeeFormView_ItemCreated"
runat="server">
<headertemplate>
<table>
<tr>
<td>
<asp:image id="LogoImage"
imageurl="~/Images/LogoImage.jpg"
alternatetext="Our Logo"
runat="server"/>
</td>
<td>
<asp:label id="HeaderLabel"
runat="server"/>
</td>
</tr>
</table>
</headertemplate>
<headerstyle horizontalalign="Center"
forecolor="White"
backcolor="LightBlue"/>
<itemtemplate>
<table>
<tr>
<td>
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td>
<h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<pagersettings position="Bottom"
mode="NextPrevious"/>
</asp:formview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Sub EmployeeFormView_ItemCreated(ByVal sender As Object, ByVal e As EventArgs)
' Use the HeaderRow property to retrieve the header row.
Dim header As FormViewRow = EmployeeFormView.HeaderRow
' Retrieve the HeaderLabel Label control from the header row.
Dim headerLabel As Label = CType(header.FindControl("HeaderLabel"), Label)
If headerLabel IsNot Nothing Then
' Display the current page number.
Dim currentPage As Integer = EmployeeFormView.PageIndex + 1
headerLabel.Text = "Page " & currentPage.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FormView HeaderTemplate Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>FormView HeaderTemplate Example</h3>
<asp:formview id="EmployeeFormView"
datasourceid="EmployeeSource"
allowpaging="true"
datakeynames="EmployeeID"
onitemcreated="EmployeeFormView_ItemCreated"
runat="server">
<headertemplate>
<table>
<tr>
<td>
<asp:image id="LogoImage"
imageurl="~/Images/LogoImage.jpg"
alternatetext="Our Logo"
runat="server"/>
</td>
<td>
<asp:label id="HeaderLabel"
runat="server"/>
</td>
</tr>
</table>
</headertemplate>
<headerstyle horizontalalign="Center"
forecolor="White"
backcolor="LightBlue"/>
<itemtemplate>
<table>
<tr>
<td>
<asp:image id="EmployeeImage"
imageurl='<%# Eval("PhotoPath") %>'
alternatetext='<%# Eval("LastName") %>'
runat="server"/>
</td>
<td>
<h3><%# Eval("FirstName") %> <%# Eval("LastName") %></h3>
<%# Eval("Title") %>
</td>
</tr>
</table>
</itemtemplate>
<pagersettings position="Bottom"
mode="NextPrevious"/>
</asp:formview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. -->
<asp:sqldatasource id="EmployeeSource"
selectcommand="Select [EmployeeID], [LastName], [FirstName], [Title], [PhotoPath] From [Employees]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
머리글 행은 또는 HeaderTemplate 속성이 FormView 설정될 때 HeaderText 컨트롤의 맨 위에 표시됩니다. 사용 된 HeaderRow 속성을 프로그래밍 방식으로 헤더 행을 FormViewRow 나타내는 개체에 액세스 합니다.
참고
속성은 HeaderRow 컨트롤이 이벤트에서 헤더 행 ItemCreated 을 FormView 만든 후에만 사용할 수 있습니다.
이 속성은 헤더 행을 프로그래밍 방식으로 조작해야 하는 경우(예: 사용자 지정 콘텐츠를 추가할 때) 일반적으로 사용됩니다. 컨트롤이 HeaderRow 렌더링된 후 FormView 속성을 수정해야 합니다. 그렇지 않으면 컨트롤이 FormView 변경 내용을 덮어씁니다.
적용 대상
추가 정보
.NET