DataControlRowType 열거형
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DetailsView 또는 GridView 컨트롤과 같은 데이터 컨트롤에 있는 행의 기능을 지정합니다.
public enum class DataControlRowType
public enum DataControlRowType
type DataControlRowType =
Public Enum DataControlRowType
- 상속
필드
DataRow | 2 | 데이터 컨트롤의 데이터 행입니다. DataRow 행만 데이터 바인딩할 수 있습니다. |
EmptyDataRow | 5 | 데이터 바인딩된 컨트롤의 빈 행입니다. 데이터 바인딩된 컨트롤에 표시할 레코드가 없고 |
Footer | 1 | 데이터 컨트롤의 바닥글 행입니다. 바닥글 행은 데이터 바인딩할 수 없습니다. |
Header | 0 | 데이터 컨트롤의 머리글 행입니다. 머리글 행은 데이터 바인딩할 수 없습니다. |
Pager | 4 | 페이저 단추 또는 페이저 컨트롤을 표시하는 행입니다. 페이저 행은 데이터 바인딩할 수 없습니다. |
Separator | 3 | 행 구분선입니다. 행 구분선은 데이터 바인딩할 수 없습니다. |
예제
다음 코드 예제를 사용 하는 방법에 설명 합니다 DataControlRowType 작업할 때 행의 형식을 확인 하는 열거형을 GridView 컨트롤입니다. AuthorsGridView_RowCreated
메서드를 사용 하면를 CommandArgument 의 속성을 LinkButton 컨트롤은 모든 데이터 행에 대 한 고유를 GridView 컨트롤 있도록 때 행의 LinkButton 컨트롤을 클릭 하면, 올바르게 식별할 수 있습니다.
<%@ 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 Page_Load(Object sender, EventArgs e)
{
// Create a new GridView object.
GridView customersGridView = new GridView();
// Set the GridView object's properties.
customersGridView.ID = "CustomersGridView";
customersGridView.DataSourceID = "CustomersSource";
customersGridView.AutoGenerateColumns = false;
// Dynamically create the columns for the GridView control.
ButtonField addColumn = new ButtonField();
addColumn.CommandName = "Add";
addColumn.Text = "Add";
addColumn.ButtonType = ButtonType.Link;
BoundField companyNameColumn = new BoundField();
companyNameColumn.DataField = "CompanyName";
companyNameColumn.HeaderText = "Company Name";
BoundField cityColumn = new BoundField();
cityColumn.DataField = "City";
cityColumn.HeaderText = "City";
// Add the columns to the Columns collection
// of the GridView control.
customersGridView.Columns.Add(addColumn);
customersGridView.Columns.Add(companyNameColumn);
customersGridView.Columns.Add(cityColumn);
// Programmatically register the event handling methods.
customersGridView.RowCommand += new GridViewCommandEventHandler(this.CustomersGridView_RowCommand);
customersGridView.RowCreated += new GridViewRowEventHandler(this.CustomersGridView_RowCreated);
// Add the GridView object to the Controls collection
// of the PlaceHolder control.
GridViewPlaceHolder.Controls.Add(customersGridView);
}
void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple ButtonField columns are used, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Add")
{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection. Use the
// CommandSource property to access the GridView control.
GridView customersGridView = (GridView)e.CommandSource;
GridViewRow row = customersGridView.Rows[index];
// Create a new ListItem object for the customer in the row.
ListItem item = new ListItem();
item.Text = Server.HtmlDecode(row.Cells[1].Text) + " " + Server.HtmlDecode(row.Cells[2].Text);
// If the author is not already in the ListBox, add the ListItem
// object to the Items collection of a ListBox control.
if(!CustomersListBox.Items.Contains(item))
{
CustomersListBox.Items.Add(item);
}
}
}
void CustomersGridView_RowCreated(Object sender, GridViewRowEventArgs e)
{
// The GridViewCommandEventArgs class does not contain a
// property that indicates which row's command button was
// clicked. To identify which row was clicked, use the button's
// CommandArgument property by setting it to the row's index.
if(e.Row.RowType == DataControlRowType.DataRow)
{
// Retrieve the LinkButton control from the first column.
LinkButton addButton = (LinkButton)e.Row.Cells[0].Controls[0];
// Set the LinkButton's CommandArgument property with the
// row's index.
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewCommandEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewCommandEventArgs Example</h3>
<table width="100%">
<tr>
<td style="width:50%">
<asp:placeholder id="GridViewPlaceHolder"
runat="Server"/>
</td>
<td style="vertical-align:top; width:50%">
Customers: <br/>
<asp:listbox id="CustomersListBox"
runat="server"/>
</td>
</tr>
</table>
<!-- 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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
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 Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' Create a new GridView object.
Dim customersGridView As New GridView()
' Set the GridView object's properties.
customersGridView.ID = "CustomersGridView"
customersGridView.DataSourceID = "CustomersSource"
customersGridView.AutoGenerateColumns = False
' Dynamically create the columns for the GridView control.
Dim addColumn As New ButtonField()
addColumn.CommandName = "Add"
addColumn.Text = "Add"
addColumn.ButtonType = ButtonType.Link
Dim companyNameColumn As New BoundField()
companyNameColumn.DataField = "CompanyName"
companyNameColumn.HeaderText = "Company Name"
Dim cityColumn As New BoundField()
cityColumn.DataField = "City"
cityColumn.HeaderText = "City"
' Add the columns to the Columns collection
' of the GridView control.
customersGridView.Columns.Add(addColumn)
customersGridView.Columns.Add(companyNameColumn)
customersGridView.Columns.Add(cityColumn)
' Programmatically register the event handling methods.
AddHandler customersGridView.RowCommand, AddressOf CustomersGridView_RowCommand
AddHandler customersGridView.RowCreated, AddressOf CustomersGridView_RowCreated
' Add the GridView object to the Controls collection
' of the PlaceHolder control.
GridViewPlaceHolder.Controls.Add(customersGridView)
End Sub
Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
' If multiple ButtonField columns are used, use the
' CommandName property to determine which button was clicked.
If e.CommandName = "Add" Then
' Convert the row index stored in the CommandArgument
' property to an Integer.
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection. Use the
' CommandSource property to access the GridView control.
Dim customersGridView As GridView = CType(e.CommandSource, GridView)
Dim row As GridViewRow = customersGridView.Rows(index)
' Create a new ListItem object for the customer in the row.
Dim item As New ListItem()
item.Text = Server.HtmlDecode(row.Cells(1).Text) + " " + Server.HtmlDecode(row.Cells(2).Text)
' If the author is not already in the ListBox, add the ListItem
' object to the Items collection of a ListBox control.
If Not CustomersListBox.Items.Contains(item) Then
CustomersListBox.Items.Add(item)
End If
End If
End Sub
Sub CustomersGridView_RowCreated(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
' The GridViewCommandEventArgs class does not contain a
' property that indicates which row's command button was
' clicked. To identify which row was clicked, use the button's
' CommandArgument property by setting it to the row's index.
If e.Row.RowType = DataControlRowType.DataRow Then
' Retrieve the LinkButton control from the first column.
Dim addButton As LinkButton = CType(e.Row.Cells(0).Controls(0), LinkButton)
' Set the LinkButton's CommandArgument property with the
' row's index.
addButton.CommandArgument = e.Row.RowIndex.ToString()
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridViewCommandEventArgs Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridViewCommandEventArgs Example</h3>
<table width="100%">
<tr>
<td style="width:50%">
<asp:placeholder id="GridViewPlaceHolder"
runat="Server"/>
</td>
<td style="vertical-align:top; width:50%">
Customers: <br/>
<asp:listbox id="CustomersListBox"
runat="server"/>
</td>
</tr>
</table>
<!-- 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="CustomersSource"
selectcommand="Select [CustomerID], [CompanyName], [City] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
설명
DataControlRowType 열거형 데이터 컨트롤에 있는 행의 함수를 식별 합니다. 사용 되는 DetailsView 및 GridView 데이터를 표시 하는 행 및 다른 사용자를 표시 하는 행을 구분 하기 위해 컨트롤 인터페이스 (UI) 요소를 머리글 행, 행 구분 기호, 페이저 단추 등입니다.
사용할 수는 DataControlRowType 의 형식을 식별 하는 열거형을 GridViewRow 또는 DetailsViewRow 전체를 열거 하는 경우 개체를 GridViewRowCollection 또는 DetailsViewRowCollection 컬렉션입니다. 행을 만드는 데이터 컨트롤을 작성 하는 경우 사용할 수 있습니다는 DataControlRowType 컨트롤의 다른 행의 기능을 식별 하는 열거형입니다.