Library tutorials & articles
Creating a Master-detail page
- Introduction
- Getting Started
- The Master Detail Code
Getting Started
Now that we have a sense of what we need let's start creating the .aspx page.
Ok, we'll just start of by adding a Page directive, where we define the language we are going to use for this page and what codebehind we want to use. Also take note of the Import directive as we need this throughout the page: <%@ Page Language="C#" Codebehind="MasterDetail.aspx.cs" Inherits="MasterDetail.MasterDetail" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Master-Detail</title>
<style type="text/css">
h1 { font-family: verdana; font-weight: bold; font-size: 16px; color: red; padding-bottom: 5px; margin-bottom: 0px; }
td { font-family: verdana; font-size: 12px; }
</style>
</head>
<body>
I've also added a couple of styles to the page, but this is optional.
Now that the base is in place we need to add the first Repeater control, and define the ItemTemplate: <asp:repeater id="Categories" runat="server">
<itemtemplate>
<h1><%# ((DataRowView) Container.DataItem)["CategoryName"] %></h1>
The preceding code very simple stuff, the only thing that may be new to you is the way I databind the 'CategoryName' field; Instead of using the 'standard' way, namely by using DataBinder.Eval(), I simply cast Container.DataItem to a DataRowView (this is why we needed that Import directive) and then refer to the field I want to print to the screen.
Next we need to add the second the Repeater control, the one that will display all products within the respective categories: <asp:repeater id="Products" runat="server">
<headertemplate>
<table cellpadding="2" cellspacing="1" bgcolor="#666666" width="490">
<tr bgcolor="#ffffff">
<td width="300"><b>ProductName</b></td>
<td width="150"><b>QuantityPerUnit</b></td>
<td width="20"><b>UnitPrice</b></td>
<td width="20"><b>UnitsInStock</b></td>
</tr>
</headertemplate>
<itemtemplate>
<tr bgcolor="#ffffff">
<td width="300"><%# ((DataRowView) Container.DataItem)["ProductName"] %></td>
<td width="150"><%# ((DataRowView) Container.DataItem)["QuantityPerUnit"] %></td>
<td width="20"><%# DataBinder.Eval(Container.DataItem, "UnitPrice", "{0:c}") %></td>
<td width="20"><%# ((DataRowView) Container.DataItem)["UnitsInStock"] %></td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:repeater>
Once again, simple stuff, although there is one thing you might want to take note of; when I databind the 'UnitPrice' column I use the 'standard' approach as it allows for quick and simple string formatting. By adding "{0:c}" the output is formatted as currency.
Finally we'll just clean up before continuing on to the codebehind file: </itemtemplate>
<separatortemplate>
<br/><br/>
</separatortemplate>
</asp:repeater>
</body>
</html>
Related articles
Related discussion
-
Gizmox Announces release of Visual WebGui SDK version 6.2.2
by Visual WebGui (0 replies)
-
Error 4 Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
by lbargers (3 replies)
-
How to receive data in web server sending from GPRS modem
by AshokSingh (1 replies)
-
Working with frames in c# .net
by pulak2008 (0 replies)
-
Time Out Problem
by lorrainepetty (1 replies)
Related podcasts
-
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
.net developer
in Rijswijk (€2K-€4K per annum)
Events coming up
-
Dec
3
An afternoon of SQL Server Data Services and ASP.NET Dynamic Data
Bradford, United Kingdom
This event is in association with Black Marble. In the morning Black Marble will be presenting on Microsoft "Oslo": The Future of Enterprise Applications. To find out more about this please follow the link on the right.
hi,
i am trying to transfer Invoice type,Invoice no and Invoice Date as per given below code But unable to access the value on the second page pls help me how it is possible
I am trying to test your code, so i found this below error:
First all:I only put the Code into a web application folder,not user the vs.net to do,but when i try to browse the page,the application error tell me
Second:I created a solution in vs.net,above the error is losed,but the .aspx page not display the result,why?
My sql server connection string is right!
This thread is for discussions of Creating a Master-detail page.