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.


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.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head id="Head1" runat="server">
<title>Untitled Page</title>
	<form id="form1" runat="server">
		<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" >
		   <asp:ControlParameter Name="stor_id" ControlID="GridView1" />
</html> (C) 2018    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.