Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ZAMBAK_IT_ExpressionWeb2

.pdf
Скачиваний:
137
Добавлен:
24.03.2015
Размер:
5.38 Mб
Скачать

Click Test Query to preview the data returned by this data source and click

Finish.

The connection between the database and web page is completely created. Now

you need to select the control through which you want to show the data. You can use the DataList control to show all records.

Drag the DataList control to the page and choose Data Source.

Choosing data source

Creating a Dynamic Web Site 131

Now you have the following figure on the page.

Save and preview the page.

You see that all selected data is sorted in a descending order and shown on the page.

You can make some changes in the formatting.

Click the Edit Templates link.

132Chapter 7

Select ItemTemplate for Display and make your desired changes.

Save and preview the page.

You need to show the picture instead of writing its name.

Drag the Image control from ASP.NET Controls>Standard and click the

Edit DataBindings link.

Choose ImageURL, select pic_small for Bound to, and type images/types/{0} for Format in the Field binding section.

Specifying the image data bindings

Creating a Dynamic Web Site 133

Choose AlternateText, select title for Bound to in the Field binding section and click OK.

Save and preview the page.

You have created a page where there is a small picture and short information about each type. When you click each type, a big picture and long information about that type should show on a new page. If you create a static page, preparing a new page for each type takes too much time and work. But you can do that dynamically by preparing only one page.

Open the page which will show a big picture and long information of each type, each_type.aspx.

Click the Create Custom Content link to add your content into the main region.

Drag the AccessDataSource control to the page from ASP.NET Controls>Data.

Click the Configure Data Source link and choose a database.

134Chapter 7

Select the fields to retrieve data from your database.

Click the WHERE button to add one condition.

Specify a parameterized value that gets their values at runtime, click the Add button and then OK.

You specify the id number and it shows that record. Here the default value is set to -1 and will not be shown any records. This value is assigned at runtime.

Adding conditions to the Where clause

After the adding Where Clause, click the Next button and then the Test Query button to preview the data.

Creating a Dynamic Web Site 135

Type 1 for Value to show the first record and click OK.

If the first record information is shown as the following, click the Finish button.

The access data source is ready and now you need a control which can show only one record’s information. That is the FormView control.

Drag the FormView control to the page from ASP.NET Controls>Data and choose Data Source.

Save and preview the page, but no record is shown because there is no record whose id equals to -1.

Add the following parameter to the page in the address bar and press the

Enter key.

each_type.aspx?which_type=1

Now you see the first record’s information.

136Chapter 7

Make changes to get a good result using Edit Templates.

Now you need to return to the types page and create the hyperlink to the each_type.aspx page with parameter.

Open the types.aspx page and click Edit Templates.

Creating a Dynamic Web Site 137

Drag the Hyperlink control to the page from ASP.NET Controls>Standard and click Edit DataBindings.

In the Text section, select title for the Bound to.

Specifying hyperlink data bindings

In the NavigateUrl section, select id for Bound to and type the following code for Format and click OK.

each_type.aspx?which_type={0}

Save and preview the page, now you see the title hyperlinked. When you click the hyperlink, the page each_type.aspx shows the clicked record’s information.

138Chapter 7

Now you can delete titleLabel in the Edit Templates because it is no more required.

When you prepare a news part for your web site, the last news is usually shown on the home page. You can also show the last news on the home page of your web site.

Open the home page default.aspx and click the Create Custom Content link.

Drag the AccessDataSource control to the page from ASP.NET Controls>Data and click Configure Data Source.

Choose a Database and click Next.

Choose ‘Specify a custom SQL statement or stored procedure’ and click the Next button.

Type the following code for the SQL Statement in the SELECT tab and click

Next.

SELECT TOP 1 * FROM [types] ORDER BY [id] DESC

Creating a SQL statement

Creating a Dynamic Web Site 139

Click the Test Query button to preview the data returned and click Finish.

Drag the FormView control to the page from ASP.NET Controls>Data and choose Data Source.

Make desired changes in the formatting of the ItemTemplate.

Save and preview the page.

140Chapter 7

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]