DetailsViewRowCollection 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 DetailsViewRow objek dalam DetailsView kontrol.
public ref class DetailsViewRowCollection : System::Collections::ICollection
public class DetailsViewRowCollection : System.Collections.ICollection
type DetailsViewRowCollection = class
interface ICollection
interface IEnumerable
Public Class DetailsViewRowCollection
Implements ICollection
- Warisan
-
DetailsViewRowCollection
- Penerapan
Contoh
Contoh kode berikut menunjukkan cara melakukan iterasi melalui DetailsViewRow objek dalam Rows kumpulan DetailsView kontrol. Nilai setiap baris kemudian ditampilkan di halaman.
<%@ 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 SubmitButton_Click(Object sender, EventArgs e)
{
// Use the Count property to determine whether the
// Rows collection contains any item.
if (ItemDetailsView.Rows.Count > 0)
{
// Iterate through the Rows collection and display
// the value of each field.
MessageLabel.Text = "The row values are: <br/><br/>";
foreach (DetailsViewRow row in ItemDetailsView.Rows)
{
// Use the Text property to access the value of
// each cell. In this example, the cells in the
// first column (index 0) contains the field names,
// while the cells in the second column (index 1)
// contains the field value.
MessageLabel.Text += row.Cells[0].Text + " = " +
row.Cells[1].Text + "<br/>";
}
}
else
{
MessageLabel.Text = "No items.";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewRowCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewRowCollection Example</h3>
<asp:detailsview id="ItemDetailsView"
datasourceid="DetailsViewSource"
allowpaging="true"
autogeneraterows="false"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</fields>
</asp:detailsview>
<br/>
<asp:button id="SubmitButton"
text="Display Row Values"
onclick="SubmitButton_Click"
runat="server"/>
<br/><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="DetailsViewSource"
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 SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
' Use the Count property to determine whether the
' Rows collection contains any item.
If ItemDetailsView.Rows.Count > 0 Then
' Iterate through the Rows collection and display
' the value of each field.
MessageLabel.Text = "The row values are: <br/><br/>"
Dim row As DetailsViewRow
For Each row In ItemDetailsView.Rows
' Use the Text property to access the value of
' each cell. In this example, the cells in the
' first column (index 0) contains the field names,
' while the cells in the second column (index 1)
' contains the field value.
MessageLabel.Text &= row.Cells(0).Text & " = " & _
row.Cells(1).Text & "<br/>"
Next
Else
MessageLabel.Text = "No items."
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>DetailsViewRowCollection Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>DetailsViewRowCollection Example</h3>
<asp:detailsview id="ItemDetailsView"
datasourceid="DetailsViewSource"
allowpaging="true"
autogeneraterows="false"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="Address"
headertext="Address"/>
<asp:boundfield datafield="City"
headertext="City"/>
<asp:boundfield datafield="PostalCode"
headertext="ZIP Code"/>
<asp:boundfield datafield="Country"
headertext="Country"/>
</fields>
</asp:detailsview>
<br/>
<asp:button id="SubmitButton"
text="Display Row Values"
onclick="SubmitButton_Click"
runat="server"/>
<br/><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="DetailsViewSource"
selectcommand="Select [CustomerID], [CompanyName], [Address],
[City], [PostalCode], [Country] From [Customers]"
connectionstring=
"<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server"/>
</form>
</body>
</html>
Keterangan
Kelas DetailsViewRowCollection ini digunakan untuk menyimpan dan mengelola kumpulan DetailsViewRow objek dalam DetailsView kontrol. Setiap baris dalam kontrol diwakili DetailsView oleh DetailsViewRow objek. Kontrol DetailsView menggunakan DetailsViewRowCollection kelas untuk propertinya Rows .
Nota
Properti Rows hanya berisi baris data. Untuk mengakses baris header, baris footer, baris pager atas, dan baris pager bawah, gunakan HeaderRowproperti , , FooterRowTopPagerRow, dan BottomPagerRow .
Kelas DetailsViewRowCollection ini mendukung beberapa cara untuk mengakses item dalam koleksi:
Gunakan pengindeks Item[] untuk langsung mengambil DetailsViewRow 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 |
|---|---|
| DetailsViewRowCollection(ArrayList) |
Menginisialisasi instans DetailsViewRowCollection baru kelas menggunakan objek yang ditentukan ArrayList . |
Properti
| Nama | Deskripsi |
|---|---|
| Count |
Mendapatkan jumlah item dalam DetailsViewRowCollection objek. |
| IsReadOnly |
Mendapatkan nilai yang menunjukkan apakah baris dalam DetailsViewRowCollection objek dapat dimodifikasi. |
| IsSynchronized |
Mendapatkan nilai yang menunjukkan apakah objek disinkronkan DetailsViewRowCollection (utas aman). |
| Item[Int32] |
DetailsViewRow Mendapatkan objek dari koleksi pada indeks yang ditentukan. |
| SyncRoot |
Mendapatkan objek yang digunakan untuk menyinkronkan akses ke koleksi. |
Metode
| Nama | Deskripsi |
|---|---|
| CopyTo(DetailsViewRow[], Int32) |
Menyalin semua item dari objek ini DetailsViewRowCollection ke objek yang ditentukan Array , dimulai dari indeks yang ditentukan di Array. |
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetEnumerator() |
Mengembalikan enumerator yang berisi semua DetailsViewRow objek dalam DetailsViewRowCollection objek. |
| 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 objek ini DetailsViewRowCollection ke objek yang ditentukan Array , dimulai dari indeks yang ditentukan di Array. |
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. |