plain text, while the PhotoURL field contains the path to a picture in a folder named FlowerPix. You can use a DataList control to display the actual picture to which each PhotoURL refers. There s nothing special about how you initially create the control. The steps, as usual, are: 1. Drag a DataList control from the Data group in the Toolbox onto any .aspx page or Content Placeholder. 2. From the DataList control s Common Tasks menu, select Choose Data Source.. 3. Choose Database, then click OK. 4. Choose your standard connection string and click Next. 5. Choose your table or view and columns to display. For this example, I ll retrieve the PhotoCaption and PhotoURL fields from the Photos table, as in Figure 12-48. 6. Click Next and Finish. In Design view, the DataList control appears with the usual field names and placeholders (abc for the text fields). In a Web browser, you still only see the links to the images, for example ~/Images/FlowerPix/Flower01.jpg rather than the actual photo. To get the photo to show, you need to edit the DataList control s ItemTemplate. As always, you can edit the template by choosing Edit Templates from the control s Common Tasks menu, or by right-clicking the control and choosing Edit Templates.Item Template. The ItemTemplate is like a miniature page that defines how each record from the underlying table will be displayed on the page. Initially the ItemTemplate just shows each field name as text typed right into the template, and each field as a Label control, as shown in Figure 12-49. Figure 12-48: Binding DataList control to fields from the Photos table. Chapter 12: Using Data in Web Pages 303
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.
This entry was posted
on Sunday, October 14th, 2007 at 1:05 am and is filed under Linux.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.