DetailsView.Rows 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DetailsViewRow 컨트롤의 데이터 행을 나타내는 DetailsView 개체의 컬렉션을 가져옵니다.
public:
virtual property System::Web::UI::WebControls::DetailsViewRowCollection ^ Rows { System::Web::UI::WebControls::DetailsViewRowCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.WebControls.DetailsViewRowCollection Rows { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Rows : System.Web.UI.WebControls.DetailsViewRowCollection
Public Overridable ReadOnly Property Rows As DetailsViewRowCollection
속성 값
DetailsViewRowCollection 컨트롤의 모든 데이터 행이 들어 있는 DetailsView입니다.
- 특성
예제
다음 코드 예제에서는 컨트롤의 데이터 행 DetailsView 에 Rows 액세스 하는 속성을 사용 하는 방법을 보여 줍니다. 데이터 행은 컨트롤에서 필드 값을 검색하는 DetailsView 데 사용됩니다.
<%@ 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 CustomerDetailView_ItemCommand(Object sender, DetailsViewCommandEventArgs e)
{
// Use the CommandName property to determine which button
// was clicked.
if (e.CommandName == "Add")
{
// Add the current store to the contact list.
// Get the row that contains the store name. In this
// example, the store name is in the second row (index 1)
// of the DetailsView control.
DetailsViewRow row = CustomerDetailView.Rows[1];
// Get the store's name from the appropriate cell.
// In this example, the store name is in the second cell
// (index 1) of the row.
String name = row.Cells[1].Text;
// Create a ListItem object with the store's name.
ListItem item = new ListItem(name);
// Add the ListItem object to the ListBox, if the
// item doesn't already exist.
if (!ContactListBox.Items.Contains(item))
{
ContactListBox.Items.Add(item);
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
DetailsView ItemCommand Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>
DetailsView ItemCommand Example</h3>
<asp:DetailsView ID="CustomerDetailView"
DataSourceID="DetailsViewSource"
AutoGenerateRows="false"
DataKeyNames="CustomerID"
AllowPaging="true"
OnItemCommand="CustomerDetailView_ItemCommand"
runat="server">
<FieldHeaderStyle BackColor="Navy" ForeColor="White" />
<Fields>
<asp:BoundField DataField="CustomerID" HeaderText="Store ID" />
<asp:BoundField DataField="CompanyName" HeaderText="Store Name" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:ButtonField CommandName="Add" Text="Add Contact" />
</Fields>
</asp:DetailsView>
<hr />
Contacts:<br />
<asp:ListBox ID="ContactListBox" runat="server" />
<!-- 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="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</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 CustomerDetailView_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs)
' Use the CommandName property to determine which button
' was clicked.
If e.CommandName = "Add" Then
' Add the current store to the contact list.
' Get the row that contains the store name. In this
' example, the store name is in the second row (index 1)
' of the DetailsView control.
Dim row As DetailsViewRow = CustomerDetailView.Rows(1)
' Get the store's name from the appropriate cell.
' In this example, the store name is in the second cell
' (index 1) of the row.
Dim name As String = row.Cells(1).Text
' Create a ListItem object with the store's name.
Dim item As New ListItem(name)
' Add the ListItem object to the ListBox, if the
' item doesn't already exist.
If Not ContactListBox.Items.Contains(item) Then
ContactListBox.Items.Add(item)
End If
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>
DetailsView ItemCommand Example</title>
</head>
<body>
<form id="Form1" runat="server">
<h3>
DetailsView ItemCommand Example</h3>
<asp:DetailsView ID="CustomerDetailView"
DataSourceID="DetailsViewSource"
AutoGenerateRows="false"
DataKeyNames="CustomerID"
AllowPaging="true"
OnItemCommand="CustomerDetailView_ItemCommand"
runat="server">
<FieldHeaderStyle BackColor="Navy" ForeColor="White" />
<Fields>
<asp:BoundField DataField="CustomerID" HeaderText="Store ID" />
<asp:BoundField DataField="CompanyName" HeaderText="Store Name" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:ButtonField CommandName="Add" Text="Add Contact" />
</Fields>
</asp:DetailsView>
<hr />
Contacts:<br />
<asp:ListBox ID="ContactListBox" runat="server" />
<!-- 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="DetailsViewSource" runat="server"
ConnectionString=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
InsertCommand="INSERT INTO [Customers]([CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country]) VALUES (@CustomerID, @CompanyName, @Address, @City, @PostalCode, @Country)"
SelectCommand="Select [CustomerID], [CompanyName],
[Address], [City], [PostalCode], [Country] From
[Customers]">
</asp:SqlDataSource>
</form>
</body>
</html>
설명
Rows 속성(컬렉션)은 컨트롤에 데이터 행을 DetailsView 저장하는 데 사용됩니다. 컨트롤은 DetailsView 데이터 원본의 Rows 각 레코드에 대한 개체를 DetailsViewRow 만든 다음 컬렉션에 개체를 추가하여 컬렉션을 자동으로 채웁니다. 이 속성은 일반적으로 컨트롤의 특정 행에 액세스 하거나 행의 전체 컬렉션을 반복 하는 데 사용 됩니다.
참고
데이터 행만 컬렉션에 Rows 저장됩니다. DetailsViewRow 머리글, 바닥글 및 호출기 행을 나타내는 개체는 컬렉션에 포함되지 않습니다.