CommandField.ShowInsertButton 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.
Mendapatkan atau mengatur nilai yang menunjukkan apakah tombol Baru ditampilkan di CommandField bidang.
public:
virtual property bool ShowInsertButton { bool get(); void set(bool value); };
public virtual bool ShowInsertButton { get; set; }
member this.ShowInsertButton : bool with get, set
Public Overridable Property ShowInsertButton As Boolean
Nilai Properti
true untuk menampilkan tombol Baru dalam CommandField; jika tidak, false. Defaultnya adalah false.
Contoh
Contoh kode berikut menunjukkan cara menggunakan ShowInsertButton properti untuk menampilkan tombol Baru dalam DetailsView kontrol, yang memungkinkan pengguna untuk menambahkan rekaman baru ke sumber data.
<%@ 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 runat="server">
<title>CommandField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField Example</h3>
<asp:detailsview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneraterows="false"
datakeynames="CustomerID"
allowpaging="true"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"/>
<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"/>
<asp:commandfield showinsertbutton="true"
showheader="true"
headertext="Add Customer"/>
</fields>
</asp:detailsview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</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">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CommandField Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>CommandField Example</h3>
<asp:detailsview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneraterows="false"
datakeynames="CustomerID"
allowpaging="true"
runat="server">
<fields>
<asp:boundfield datafield="CustomerID"
headertext="Customer ID" />
<asp:boundfield datafield="CompanyName"
headertext="CompanyName"/>
<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"/>
<asp:commandfield showinsertbutton="true"
showheader="true"
headertext="Add Customer"/>
</fields>
</asp:detailsview>
<!-- 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="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
insertcommand="Insert Into [Customers]([CustomerID], [CompanyName], [City], [PostalCode], [Country]) Values (@CustomerID, @CompanyName, @City, @PostalCode, @Country)"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Keterangan
ShowInsertButton Gunakan properti untuk menentukan apakah tombol Baru ditampilkan dalam bidangCommandField. Tombol Baru ditampilkan hanya sekali di CommandField bidang dan memungkinkan pengguna untuk menambahkan rekaman baru di sumber data.
Nota
Properti ini hanya berlaku untuk kontrol terikat data yang mendukung operasi penyisipan, seperti DetailsView kontrol.
Saat pengguna mengklik tombol Baru, kontrol input ditampilkan untuk setiap bidang yang ditampilkan dalam kontrol terikat data, memungkinkan pengguna memasukkan nilai untuk rekaman baru. Tombol Baru diganti dengan tombol Sisipkan dan tombol Batal, dan semua tombol perintah lainnya di CommandField bidang disembunyikan. Mengklik tombol Sisipkan menambahkan rekaman ke sumber data, sedangkan mengklik tombol Batalkan membatalkan operasi.
Nota
Saat kontrol terikat data digunakan dalam kombinasi dengan kontrol sumber data (seperti SqlDataSource kontrol), kontrol terikat data dapat memanfaatkan kemampuan kontrol sumber data dan menyediakan fungsi penyisipan otomatis. Untuk sumber data lain, Anda harus menyediakan rutinitas untuk melakukan operasi penyisipan selama peristiwa yang sesuai untuk kontrol terikat data.
ButtonType Saat properti CommandField bidang diatur ke ButtonType.Button atau ButtonType.Link, gunakan NewText properti untuk menentukan teks yang akan ditampilkan untuk tombol Baru. Atau, Anda dapat menampilkan gambar dengan terlebih dahulu mengatur properti ke ButtonTypeButtonType.Image lalu mengatur NewImageUrl properti.