Dreamwaver MX and ASP.NET(6)
Author:Eve Cole
Update Time:2009-05-31 21:06:05
6. Create record modification page
Related introduction (Note: In order to display the code, all the following codes have spaces after "<" and before ">". We apologize for the inconvenience!):
Adding, modifying, and deleting data are the three basic operations on the database. This section introduces the modification record part.
STEP 1 Design modification process
Generally speaking, only the specified records need to be updated, so a search page needs to be established for query, the query results will be displayed in the results page, and users can modify them. Finally, the update task is completed through the submission operation.
First, create a query page. In the process of creating a dataset, we can select the required data through the data filter Filter. Since we will click on the link in the DataList to reach this page, select the URL Parameter and use the keyword CODE to filter out the required page.
[Figure 6-1 Filtering data]
To do this, create a new modify.aspx file in the site and add the DataSet as shown above.
Step2 Create details page
In order to generate links, a navigation page should be established first. The DataGrid page created in Section 3 can be modified to achieve such a navigation effect. The style of the DataGrid is modified, and the data items can also be set to display linked text. The same function can also be achieved in DataList and Repeater, both of which set a hyperlink to the details page.
Open the original location2.aspx file and modify the original DataList style. Select DataListm and click Edit Columns (Figure 6-2). In the pop-up DataGrid style design dialog box (Figure 6-3), you can set the type of Location_name to Hyperlink. Select Location_name and click the Change Column Type button to change to Hyperlink.
[Figure 6-2 Edit Columns..]
[Figure 6-3 Setting up hyperlink]
The Hyperlink settings are as shown below:
[Figure 6-4 Setting link keywords]
The displayed data field Location_name, the connection keyword is code, and the page that needs to be jumped to is the modify.aspx page. After clicking the link, the specific URL link will be
http://yoursite/modify.aspx?CODE=The code value of the clicked record
The modify.aspx page will also query the required records from the database through the passed code value.
In order to update data in the modify.aspx page, you need to use a form. This requires binding the data record to the input box. Binding data in Dreamweaver MX is similar to that in Dreamweaver UltraDev. Set the page as shown in Figure 6-5. Create 6 new Text Fields, 1 hiddenField, and 1 submit button, and place them in appropriate locations. The hiddenField is used to save the CODE value of this record. Because the code value is a keyword, it does not need to be changed.
[Figure 6-5 modify.aspx page]
Click the Binding label and drag the specific data item to the corresponding text field. At the same time, the display type of data can be set in Format. You can also bind all properties of the text field to the data source. Select the first dropdown of the record
[Figure 6-6 Binding] [Figure 6-7 Data type selection] [Figure 6-8 Binding attributes]
List, set the text Field property bound to the data source.
STEP 3 data update
As for data update, you can click the "+" button in Server Behaviors in the Application panel and select Update Record.
[Figure 6-9 Select Update Record]
[Figure 6-10 Setting association]
In the pop-up dialog box, you need to associate the input box with the corresponding updated data source, and set the data type. Among them, CODE should be the keyword, Primary Key. Similar to the Insert Record page, you also need to set the page to which the page will jump if the page is successfully added and if the page fails to be added.
Now you can preview the finished page. Enter the URL http://yoursite/location3.aspx, and you will see the page shown in Figure 6-11.
[Figure 6-11 location3.aspx page browsing]
The Location_name item is clickable and will jump to the details page modify.aspx.
[Figure 6-12 Update page preview]
Existing data can be modified through the modify.aspx page, and data can be updated through form submission events.
The main updated code is as follows:
<MM:Update
runat="server"
CommandText='< %# "UPDATE LOCATIONS SET CITY=?, STATE_COUNTRY=?, FAX=?, TELEPHONE=?, ADDRESS=? WHERE CODE=?" % >'
ConnectionString='< %# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_location") % >'
DatabaseType='< %# System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_DATABASETYPE_location") % >'
Expression='< %# Request.Form("MM_update") = "form1" % >'
CreateDataSet="false"
SuccessURL='< %# "location3.aspx" % >'
Debug="true"
>
<Parameters>
< Parameter Name="@CITY" Value='< %# IIf((Request.Form("city") < > Nothing), Request.Form("city"), "") % >' Type="WChar" />
< Parameter Name="@STATE_COUNTRY" Value='< %# IIf((Request.Form("state") < > Nothing), Request.Form("state"), "") % >' Type="WChar" />
< Parameter Name="@FAX" Value='< %# IIf((Request.Form("fax") < > Nothing), Request.Form("fax"), "") % >' Type="WChar" />
< Parameter Name="@TELEPHONE" Value='< %# IIf((Request.Form("tele") < > Nothing), Request.Form("tele"), "") % >' Type="WChar" />
< Parameter Name="@ADDRESS" Value='< %# IIf((Request.Form("address") < > Nothing), Request.Form("address"), "") % >' Type="WChar" />
< Parameter Name="@CODE" Value='< %# IIf((Request.Form("hiddenField") < > Nothing), Request.Form("hiddenField"), "") % >' Type="WChar" />
< /Parameters >
< /MM:Update >
Dreamweaver MX uses mm:update to represent updated code. Its format is similar to MM:Insert.