Net-informations.com
SiteMap  | About    

GridView with DetailsView

The DetailsView control has very similar functionality to the GridView control. DetailsView generates a user interface similar to the Form View of a Microsoft Access database, and is typically used for updating/deleting any currently displayed record or for inserting new records.

master-details

The DetailsView control is also often used in a master-details scenario where the selected record of the master control determines the record to display in the detail view. The following ASP.NET program shows how to display a master-details data from database using GridView and DetailsView control. Here we are using master data as sales data and details as store data. When the user select a row of sales data then it displays the corresponding store details in DetailsView.

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>
		<br /><b><u>Sales Details</u></b><br /><br />
		<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
		DataKeyNames="stor_id" AutoGenerateSelectButton="true"  AllowPaging="True" pagesize ="5"  />
		<br /><b><u>Store Details</u></b><br /><br />
		<asp:DetailsView id="DetailsView1" DataSourceID="SqlDataSource2"
		DataKeyNames="stor_id" AllowPaging ="true" Runat="server" />
		<asp:SqlDataSource ID="SqlDataSource1" runat="server"
		ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
		SelectCommand="select * from sales" />
		<asp:SqlDataSource ID="SqlDataSource2" runat="server"
		ConnectionString="<%$ ConnectionStrings:SQLDbConnection %>"
		SelectCommand="select * from stores WHERE stor_id=@stor_id" >
		<SelectParameters>
		   <asp:ControlParameter Name="stor_id" ControlID="GridView1" />
		</SelectParameters>
		</asp:SqlDataSource>
	</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.