Danh mục

Display Data Using the Repeater Control

Số trang: 9      Loại file: pdf      Dung lượng: 32.57 KB      Lượt xem: 10      Lượt tải: 0    
10.10.2023

Hỗ trợ phí lưu trữ khi tải xuống: 1,000 VND Tải xuống file đầy đủ (9 trang) 0
Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

5,5 Hiển thị dữ liệu Sử dụng Repeater Control Tôi có nghe nói rằng việc kiểm soát Repeater là một điều khiển tuyệt vời cho hiển thị một danh sách chỉ đọc các giá trị, bao gồm các siêu liên kết. Làm thế nào để cư một điều khiển Repeater và tận dụng các mẫu để hiển thị các dữ liệu cách tôi muốn nó nhìn?
Nội dung trích xuất từ tài liệu:
Display Data Using the Repeater Control 5.5 Display Data Using the Repeater ControlI have heard that the Repeater control is a great control for displaying a read-only list ofvalues, including hyperlinks. How do I populate a Repeater control and take advantage oftemplates to display the data the way I want it to look?TechniqueThe Repeater control allows you to list data in various formats, such as bulleted ornumbered. 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, butalso to use a couple of different controls-a Button and HyperLink-to display another listusing the Repeater control. The second list will be displayed using the button on the samepage as the first list. The hyperlink will take you to another page to display the secondlist.A main tool in the creation of the Repeater control is the use of templates.Use of TemplatesTemplates are used within HTML and allow you to include controls in your ASP.NETWeb server controls. Within a template, you can specify various details about the area forwhich you are creating a template. Following is a list of the templates: • HeaderTemplate • ItemTemplate • FooterTemplate • AlternatingItemTemplate • SeparatorTemplateYou can get an idea of what each of the templates is used for by its name. Here is anexample of the HeaderTemplate, used in this How-To: List of Regions These lines are literally used as a template for how you want the section to be laid out, aswell as what data to display. For the ItemTemplate in this How-To, two controls aredisplayed: a button and a hyperlink, shown by this snippet of the HTML: Text= />As the name implies, the DataBinder supplies data from the data source that is specifiedfor the Repeater object. You will see how to bind the Repeater object in step 3.Creating URLs On-the-FlyIn the NavigateURL of the hyperlink that was created, you can see the columnDataItem.RegionURL being used. This is not a column that is found in the Regions tablein Northwind. This column is created within the SQL statement that is supplied to a dataadapter, by the following line of code:odaRegions = New OleDb.OleDbDataAdapter(Select RegionID, _ wfrmHowto5_5b.aspx?RegID= + Cast(RegionID as Char(2)) As RegionURL, RegionDescription From Region, BuildCnnStr((local), Northwind))The RegionURL consists of a Web Form name and the statement?RegID=Cast(RegionID as Char(2)), which ASP.NET loads into the new page and passesto the RegionID of the page, letting the code within the page read the RegionID using theRequest object, as displayed here:odaTer = New _ OleDb.OleDbDataAdapter(_ Select TerritoryDescription From Territories Where RegionID = & Request.Item(RegID), _ BuildCnnStr((local), Northwind))You will see both the creation and utilization of the URL in the steps that follow.Programming Repeater Events by Using ItemCommandWhen youre using buttons, you can program the response for when the buttons arepressed by using the ItemCommand event. This event is raised for all the controls that areused in the Repeater. You will see an example of this in step 5.StepsOpen and run the Visual Basic .NET-Chapter 5 solution. From the main page, click onthe 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 displayedusing the Repeater control. This list is displayed below the regions and contains theterritories 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 anotherRepeater 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: 3. Replace this line of code with the code displayed in Listing 5.13. This co ...

Tài liệu được xem nhiều: