Tài liệu Display Data Using the Repeater Control - Pdf 87

5.5 Display Data Using the Repeater Control
I have heard that the Repeater control is a great control for displaying a read-only list of
values, including hyperlinks. How do I populate a Repeater control and take advantage of
templates to display the data the way I want it to look?
Technique
The Repeater control allows you to list data in various formats, such as bulleted or
numbered. It relies on the use of templates to display information in a list format.
This How-To shows you how to use the Repeater control not only to display a list, but
also to use a couple of different controls-a Button and HyperLink-to display another list
using the Repeater control. The second list will be displayed using the button on the same
page as the first list. The hyperlink will take you to another page to display the second
list.
A main tool in the creation of the Repeater control is the use of templates.
Use of Templates
Templates are used within HTML and allow you to include controls in your ASP.NET
Web server controls. Within a template, you can specify various details about the area for
which you are creating a template. Following is a list of the templates:

HeaderTemplate

ItemTemplate

FooterTemplate

AlternatingItemTemplate

SeparatorTemplate
You can get an idea of what each of the templates is used for by its name. Here is an
example of the HeaderTemplate, used in this How-To:
<HeaderTemplate>
<font face="Arial Black" size="2">List of Regions </font>

BuildCnnStr("(local)", "Northwind"))
You will see both the creation and utilization of the URL in the steps that follow.
Programming Repeater Events by Using ItemCommand
When you're using buttons, you can program the response for when the buttons are
pressed by using the ItemCommand event. This event is raised for all the controls that are
used in the Repeater. You will see an example of this in step 5.
Steps
Open and run the Visual Basic .NET-Chapter 5 solution. From the main page, click on
the hyperlink with the caption How-To 5.4: Display Data Using the Repeater Control.
You will then see a page open displaying a list of the regions (see Figure 5.5).
Figure 5.5. This list includes both a button, displaying the RegionID, and a
hyperlink, displaying the region description.

If you click one of the buttons displaying the Region ID, then another list is displayed
using the Repeater control. This list is displayed below the regions and contains the
territories for the region clicked (see Figure 5.6).
Figure 5.6. Another Repeater control is utilized for this list of territories.

When you click on the hyperlinks in the list, another page displays, with yet another
Repeater control used to display the territories for the region chosen (see Figure 5.7).
1. Create a Web Form. Then place the controls listed in Table 5.8 with the following
properties set.
Table 5.8. Property Settings Repeater and HyperLink Controls
Object Property Setting
Repeater ID repRegions
Repeater ID repTeritories
HyperLink ID hplReturnToMain
NavigateURL wfrmMain.aspx
2. Switch to the HTML tab in the designer. By adding the repeaters and naming the
repeaters in step 1, you will see a line of code that looks like this:

<asp:Repeater id="repTerritories" runat="server">
<HeaderTemplate>
<br>
<font face="Arial Black" size="2">List of Territories </font>
<br>
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server"
Text= '<%# DataBinder.Eval(Container.DataItem, _
"TerritoryDescription") %> ' />
<br>


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status