DataKeyArray Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mewakili kumpulan DataKey objek. Kelas ini tidak dapat diwariskan.
public ref class DataKeyArray sealed : System::Collections::ICollection, System::Web::UI::IStateManager
public sealed class DataKeyArray : System.Collections.ICollection, System.Web.UI.IStateManager
type DataKeyArray = class
interface ICollection
interface IEnumerable
interface IStateManager
Public NotInheritable Class DataKeyArray
Implements ICollection, IStateManager
- Warisan
-
DataKeyArray
- Penerapan
Contoh
Contoh kode berikut menunjukkan cara menggunakan pengindeks untuk mengambil DataKey objek dari DataKeyArray koleksi.
<%@ 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>
Contoh kode berikut menunjukkan cara melakukan iterasi melalui DataKeyArray koleksi.
<%@ 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)
{
// Display the value of the primary key for each
// record in the GridView control.
MessageLabel.Text = "The primary key of each record displayed are: <br/><br/>";
foreach (DataKey key in CustomerGridView.DataKeys)
{
MessageLabel.Text += key.Value.ToString() + "<br/>";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head 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"/>
</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
' Display the value of the primary key for each
' record in the GridView control.
MessageLabel.Text = "The primary key of each record displayed are: <br/><br/>"
Dim key As DataKey
For Each key In CustomerGridView.DataKeys
MessageLabel.Text += key.Value.ToString() + "<br/>"
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head 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"/>
</form>
</body>
</html>
Keterangan
Kelas DataKeyArray ini digunakan untuk menyimpan dan mengelola kumpulan DataKey objek. Objek DataKey mewakili kunci utama rekaman dalam kontrol terikat data. Secara umum, kontrol terikat data yang menampilkan beberapa rekaman (seperti GridView kontrol) menggunakan DataKeyArray objek untuk menyimpan DataKey objek untuk rekaman yang ditampilkan dalam kontrol.
Kelas DataKeyArray ini mendukung beberapa cara untuk mengakses item dalam koleksi:
Gunakan pengindeks Item[] untuk langsung mengambil DataKey objek dari koleksi pada indeks berbasis nol tertentu.
GetEnumerator Gunakan metode untuk mengambil enumerator yang dapat digunakan untuk melakukan iterasi melalui koleksi.
CopyTo Gunakan metode untuk menyalin item dalam koleksi ke dalam array, yang kemudian dapat digunakan untuk mengakses item dalam koleksi.
Untuk menentukan jumlah total item dalam koleksi, gunakan Count properti .
Konstruktor
| Nama | Deskripsi |
|---|---|
| DataKeyArray(ArrayList) |
Menginisialisasi instans baru dari kelas DataKeyArray. |
Properti
| Nama | Deskripsi |
|---|---|
| Count |
Mendapatkan jumlah item dalam koleksi. |
| IsReadOnly |
Mendapatkan nilai yang menunjukkan apakah item dalam koleksi dapat dimodifikasi. |
| IsSynchronized |
Mendapatkan nilai yang menunjukkan apakah koleksi disinkronkan DataKeyArray (utas aman). |
| Item[Int32] |
DataKey Mendapatkan objek dari koleksi pada indeks yang ditentukan. |
| SyncRoot |
Mendapatkan objek yang digunakan untuk menyinkronkan akses ke koleksi. |
Metode
| Nama | Deskripsi |
|---|---|
| CopyTo(DataKey[], Int32) |
Menyalin semua item dari koleksi ini ke array DataKey objek yang ditentukan, dimulai dari indeks yang ditentukan dalam array. |
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetEnumerator() |
Mengembalikan enumerator yang berisi semua DataKey objek dalam koleksi. |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| ToString() |
Mengembalikan string yang mewakili objek saat ini. (Diperoleh dari Object) |
Implementasi Antarmuka Eksplisit
| Nama | Deskripsi |
|---|---|
| ICollection.CopyTo(Array, Int32) |
Menyalin semua item dari koleksi ini ke yang ditentukan Array, dimulai dari indeks yang ditentukan di Array. |
| IStateManager.IsTrackingViewState |
Mendapatkan nilai yang menunjukkan apakah DataKeyArray objek melacak perubahan status tampilannya. |
| IStateManager.LoadViewState(Object) |
Memuat status tampilan objek yang DataKeyArray disimpan sebelumnya. |
| IStateManager.SaveViewState() |
Menyimpan status DataKeyArray tampilan objek saat ini. |
| IStateManager.TrackViewState() |
Menandai titik awal untuk mulai melacak dan menyimpan perubahan status tampilan ke DataKeyArray objek. |
Metode Ekstensi
| Nama | Deskripsi |
|---|---|
| AsParallel(IEnumerable) |
Mengaktifkan paralelisasi kueri. |
| AsQueryable(IEnumerable) |
IEnumerable Mengonversi ke IQueryable. |
| Cast<TResult>(IEnumerable) |
Melemparkan elemen ke jenis yang IEnumerable ditentukan. |
| OfType<TResult>(IEnumerable) |
Memfilter elemen berdasarkan IEnumerable jenis tertentu. |