Using a DataList to show HyperLinks In the (Web hosting reseller)

Using a DataList to show HyperLinks In the photos example, I used a HyperLink control in a DataList ItemTemplate to show hyperlink text from a table (the PhotoCaption field), and to define where the link takes the user (the PhotoURL field). You can use the same technique to show a list of links that are stored in a Database table. In Chapter 11, I created a sample table named Links that contains two text fields named SiteName (the name of a Web site) and SiteURL (the URL of the site). It s a small sample table, as shown in Figure 12-57. But of course the technique described here would work with any number of records in a table. A DataList control containing a standard HyperLink control that s bound to the SiteName and SiteURL fields in the table will present a nice list of links. Here are the steps to create the list: 1. From the Data group in the Toolbox, drag a Data List control to any .aspx page or content placeholder. 2. From the DataList control s Common Tasks menu, select Choose Data Source.. 3. Choose Database and click OK. 4. Choose your normal connection string and click Next. 5. Choose the table that contains the site data, then choose the columns that contain the site name and URL. For my example, that would be the SiteName and SiteURL fields in the Links table, as shown in Figure 12-58. 6. Optionally, use the ORDER BY button to alphabetize the links by SiteName. 7. Click Next, then click Finish. Figure 12-57: Sample Links table with site names and URLs. Chapter 12: Using Data in Web Pages 309
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

Leave a Reply