DataKeyArray.Item[Int32] 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컬렉션의 지정한 인덱스에서 DataKey 개체를 가져옵니다.
public:
property System::Web::UI::WebControls::DataKey ^ default[int] { System::Web::UI::WebControls::DataKey ^ get(int index); };
public System.Web.UI.WebControls.DataKey this[int index] { get; }
member this.Item(int) : System.Web.UI.WebControls.DataKey
Default Public ReadOnly Property Item(index As Integer) As DataKey
매개 변수
속성 값
컬렉션의 지정된 인덱스에 있는 DataKey 입니다.
예제
다음 코드 예제에서는 인덱서를 사용 하 여 검색 하는 방법에 설명 된 DataKey 에서 개체를 DataKeyArray 컬렉션입니다.
<%@ 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 CustomerGridView_DataBound(Object sender, EventArgs e)
{
// Use the indexer to retrieve the DataKey object for the
// first record.
DataKey key = CustomerGridView.DataKeys[0];
// Display the value of the primary key for the first
// record displayed in the GridView control.
MessageLabel.Text = "The primary key of the first record displayed is " +
key.Value.ToString() + ".";
}
void CopyArray_Click(Object sender, EventArgs e)
{
DataKeyArray theKeys = CustomerGridView.DataKeys;
DataKey[] myNewArray = new DataKey[theKeys.Count];
theKeys.CopyTo(myNewArray, 0);
Label2.Visible = true;
// Display first page key values from the new array.
for (int i = 0; i < myNewArray.Length; i++)
{
Label2.Text += "<br />" + myNewArray[i].Value;
}
}
</script>
<html >
<head id="Head1" runat="server">
<title>DataKeyArray Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataKeyArray Example</h3>
<asp:gridview id="CustomerGridView"
datasourceid="CustomerDataSource"
autogeneratecolumns="true"
datakeynames="CustomerID"
allowpaging="true"
ondatabound="CustomerGridView_DataBound"
runat="server">
</asp:gridview>
<br/>
<asp:label id="MessageLabel"
forecolor="Red"
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="CustomerDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
runat="server"/>
<asp:Button ID="CopyArray"
runat="server"
Text="Copy DataKeyArray to Array"
OnClick="CopyArray_Click" />
<br />
<asp:label id="Label2"
runat="server"
Visible="false"
Text="First page of Copied Array Key Values" />
</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 CustomerGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs) Handles CustomerGridView.DataBound
' Use the indexer to retrieve the DataKey object for the
' first record.
Dim key As DataKey = CustomerGridView.DataKeys(0)
' Display the value of the primary key for the first
' record displayed in the GridView control.
MessageLabel.Text = "The primary key of the first record displayed is " & _
key.Value.ToString() & "."
End Sub
Sub CopyArray_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim theKeys As DataKeyArray = CustomerGridView.DataKeys
Dim myNewArray(theKeys.Count - 1) As DataKey
theKeys.CopyTo(myNewArray, 0)
Label2.Visible = True
' Display first page key values from the new array.
For i As Integer = 0 To myNewArray.Length - 1
Label2.Text &= "<br />" & myNewArray(i).Value
Next i
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>DataKeyArray Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DataKeyArray Example</h3>
<asp:gridview id="CustomerGridView"
datasourceid="CustomerDataSource"
autogeneratecolumns="true"
datakeynames="CustomerID"
allowpaging="true"
runat="server">
</asp:gridview>
<br/>
<asp:label id="MessageLabel"
forecolor="Red"
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="CustomerDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
<asp:Button ID="CopyArray"
runat="server"
Text="Copy DataKeyArray to Array"
OnClick="CopyArray_Click" />
<br />
<asp:label id="Label2"
runat="server"
Visible="false"
Text="First page of Copied Array Key Values" />
</form>
</body>
</html>
설명
이 인덱서를 사용 하 여 검색을 DataKey 배열 표기법을 사용 하 여 지정 된 인덱스 컬렉션에서 개체입니다. 이 속성은 읽기 전용입니다.