Parameter.DefaultValue Properti
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.
Menentukan nilai default untuk parameter, jika nilai parameter terikat untuk tidak diinisialisasi saat metode dipanggil Evaluate(HttpContext, Control) .
public:
property System::String ^ DefaultValue { System::String ^ get(); void set(System::String ^ value); };
public string DefaultValue { get; set; }
member this.DefaultValue : string with get, set
Public Property DefaultValue As String
Nilai Properti
String yang berfungsi sebagai nilai default untuk Parameter ketika nilai yang terikat tidak dapat diselesaikan atau tidak diinisialisasi.
Contoh
Contoh kode berikut menunjukkan cara mengambil satu rekaman data menggunakan ObjectDataSource kontrol dan menampilkannya dalam DetailsView kontrol. Kontrol ObjectDataSource mengambil catatan karyawan tertentu dengan memanggil GetEmployee metode EmployeeLogic kelas. Metode ini GetEmployee memerlukan parameter ID karyawan. Kontrol ObjectDataSource menggunakan QueryStringParameter objek dalam koleksinya SelectParameters untuk meneruskan ID ke GetEmployee metode dalam contoh ini.
Untuk melihat contoh implementasi EmployeeLogic kelas dan GetEmployee metode , lihat ObjectDataSource gambaran umum kelas.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %>
<%@ Page language="c#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ObjectDataSource - C# Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
datasourceid="ObjectDataSource1">
</asp:detailsview>
<!-- Security Note: The ObjectDataSource uses a QueryStringParameter,
Security Note: which does not perform validation of input from the client.
Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetEmployee"
typename="Samples.AspNet.CS.EmployeeLogic" >
<selectparameters>
<asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
</selectparameters>
</asp:objectdatasource>
</form>
</body>
</html>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %>
<%@ Page language="vb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ObjectDataSource - VB Example</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<asp:detailsview
id="DetailsView1"
runat="server"
datasourceid="ObjectDataSource1">
</asp:detailsview>
<!-- Security Note: The ObjectDataSource uses a QueryStringParameter,
Security Note: which does not perform validation of input from the client.
Security Note: To validate the value of the QueryStringParameter, handle the Selecting event. -->
<asp:objectdatasource
id="ObjectDataSource1"
runat="server"
selectmethod="GetEmployee"
typename="Samples.AspNet.VB.EmployeeLogic" >
<selectparameters>
<asp:querystringparameter name="EmployeeID" querystringfield="empid" defaultvalue="-1" />
</selectparameters>
</asp:objectdatasource>
</form>
</body>
</html>
Keterangan
Properti DefaultValue digunakan dalam skenario di mana parameter terikat ke nilai, tetapi nilainya adalah null atau tidak dapat diselesaikan saat Parameter objek dievaluasi.
DefaultValue Jika properti parameter diubah, OnParameterChanged metode dipanggil.