Net-informations.com
SiteMap  | About    

Detailsview Insert

The GridView control shows all of the records from its data source control at once, but the DetailsView control displays one row from a data source at a time by rendering an HTML table. The DetailsView supports inserting is to add a SqlDataSource control to the page that has been configured to include the INSERT statements. To enable insert command, set the AutoGenerateInsertButton property to true.

  AutoGenerateInsertButton="true"

detailsview-insert

Each DetailsView field has an InsertVisible property that can be set through the Fields dialog box. If this property is set to False, the field does not appear when adding a new record. The following ASP.NET program shows how to insert data in a database using DetailsView control.

Default.aspx

  

<!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 id="Head1" runat="server">
	<title>Untitled Page</title>
</head>
<body>
	<form id="form1" runat="server">
	<div>
		<asp:DetailsView id="DetailsView1" DataSourceID="SqlDataSource1"
		AllowPaging ="true" Runat="server" AutoGenerateInsertButton="true" />
		<asp:SqlDataSource ID="SqlDataSource1" runat="server"
		ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
		SelectCommand="select * from stores"
		InsertCommand="INSERT [stores] ([stor_id],[stor_name],[stor_address],[city],[state],[zip])
		VALUES (@stor_id,@stor_name,@stor_address,@city,@state,@zip)" />
	</div>
	</form>
</body>
</html>







net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.