Chapter 5 Note Menu Columns and Implementation of Replies
The home page completed in Chapter 4 is actually very imperfect. First, there are no links in the note menu columns and cannot be clicked; second, if you click on the note title, you cannot link to the reply page; Third, if you click on the author, you cannot link to the author's information. These functions will be improved in this chapter.
: Modify the hyperlink of the menu column in the template bkblog.dwt.aspx, and then update all web pages; when opening the homepage, browse to display the content of the study notes in descending order of time, click on the menu column, It can also display study note contents in descending order of time according to columns.
5.1.1 Create template menu
(1) Open the template bkblog.dwt.aspx, select dynamic text (menuda.LM), create a hyperlink, link to the homepage (index.aspx), select [Code Display View], and move the mouse to The place where the red vertical line is shown in Figure 5-1-1. (No special instructions below, all symbols are English characters)
Figure 5-1-1 Move the mouse to the link attribute
(2) Enter "?menanw=" (menanw is the parameter variable), switch to the [Binding] panel, drag the field LMID under the data set (menuda) to just now After the input equal sign, the result is shown in Figure 5-1-2:
Figure 5-1-2 Insert dynamic attributes (a.href)
(3) Switch to the [Server Behavior] panel, you can see that a server behavior has been added: dynamic attributes (a.href), as shown in Figure 5-1-3 :
Figure 5-1-3 Server Behavior Panel
(4) Select the "Home" menu and create a link to index.aspx; select "Contact Us" and create a link to mailto:[email protected].
(5) Save the bkblog.dwt.aspx template, and the dialog box shown in Figure 5-1-4 will pop up.
Figure 5-1-4 Update template file dialog box.
(6) Click the "Update" button to complete the note menu columns and update the homepage index.aspx.
5.1.2 Implement column display on the home page
(1) Open the home page index.aspx, switch to the [Server Behavior] panel, double-click the data set (Ztre), and in the pop-up data set dialog box, click the "Advanced" button. As shown in Figure 5-1-5. Select the SQL command in the [SQL] text area to copy. It is recommended to paste it into the newly created Notepad or Word text. It will be of great use in subsequent steps (you can skip this step if you are familiar with SQL language) .
Figure 5-1-5 Dataset Advanced Dialog Box
(2) Click the "Simple" button, select the filter field as LMID in the [Filter] drop-down menu, select "URL Parameter" as the parameter transfer method, and the input parameter variable is menanw. Press the "OK" button, the result is shown in Figure 5-1-6:
Figure 5-1-6 Modify the Ztre data set to filter
(3) Browse the home page with IE, but the browsing results are not recorded, as shown in Figure 5-1-7
Figure 5-1-7 Home page browsing picture
(4) In the home page IE browsing, click the link "Network Programming", the result is shown in Figure 4-3-3 in the previous chapter, showing all network programming study notes.
"Wait a minute, this is not in line with the original design idea! It can only be displayed by columns, not all study notes!" There is also a problem of data transfer between ASP.NET pages: data between Forms in Windows applications Transfer can be achieved by defining global variables (Public static variables) and other methods. However, these methods cannot be used to transfer data between Web pages in ASP.NET. For example: when you click on the data set navigation bar, the data of Ztre_currentPage will be transferred, but the data of menanw cannot be transferred. That is to say, when you click on any hyperlink of the data set navigation bar, the data transferred by menan will always be null, which is not possible. It not only realizes column display, but also performs paging display under the columns at the same time. Here is a solution using session to pass parameters.
(5) In order to pass the parameter variable menanw to session("menanw"), switch to the code view and insert the code shown in the red circle in Figure 5-1-8 before the <html> tag.
Figure 5-1-8 Insert the page into index.aspx to load the default function
(6) Select the data set (Ztre) in the [Server Behavior] panel, as shown in Figure 5-1-9, the black part is the data set (Ztre) Definition code.
Figure 5-1-9 Code of data set Ztre
(7) Find the code:
CommandText='<%# "SELECT * FROM ZTRE WHERE LMID = ? ORDER BY ZITIME ASC" %>'
Change the above code to:
CommandText=' <%# IIf(((request.QueryString("menanw")<>nothing) or Request.QueryString("Ztre_CurrentPage") <> Nothing),"SELECT * FROM ZTRE WHERE LMID = ? ORDER BY ZITIME DESC","SELECT * FROM ZTRE ORDER BY ZITIME DESC") %>'
(8) Code found:
<Parameter Name="@LMID" Value='<%# IIf((request.QueryString("menanw") <> Nothing), request. QueryString("menanw"), "") %>' Type="Integer" /></Parameters></MM:DataSet>
Change the above code to:
<Parameter Name="@LMID" Value='<% # IIf((session("menanw") <> Nothing), session("menanw"), "") %>' Type="Integer" /></Parameters></MM:DataSet>
(9) Perform IE Browse, the result is shown in Figure 4-3-3 of Chapter 4. Complete the established design ideas.
design idea of the reply page: By clicking on the title of the note, a page can be linked, including the note and all corresponding replies. From the previous section, it can be seen that this is not difficult. It can be achieved by passing the code parameters of this note only on the hyperlink of the note title.
5.2.1 Basic page design
(1) Create a new ASP.NET VB dynamic page hf.aspx generated by the template bkblog.dwt.aspx, insert the table ztre in the mainbody editable area, and perform related designs. The result is shown in Figure 5-2 -1 shows:
Figure 5-2-1 Table ztre design diagram
(2) Start Access2003, establish FH table, YH table connection query HFRE, in fact the connection view and display fields are shown in Figure 5-2-2.
Figure 5-2-2 Query the relevant design of HFRE
(3) Follow steps (1)-(3) in section 4.2.2 Data Set to add the data set Ztre, drag the fields to the corresponding positions, and perform dynamic text (Ztre. ZYTEXT) format setting, the result is shown in Figure 5-2-3:
Figure 5-2-3 Bind data to table ztre
(4) Modify the data set Ztre to filter, the filter field is ZTID, select "URL parameter" as the parameter transfer method, and the input parameter variable is ztanw.
(5) Add the data set Hfre, the filter field is ZTID, select "URL parameter" as the parameter transfer method, and the input parameter variable is ztanw. The result is shown in Figure 5-2-4:
Figure 5-2-4 Design of the data set Hfre
(6) Drag the data set Hfre field to the corresponding position of the table ztre, set the format setting of the dynamic text (Htre.HFTEXT) to "Encoding—HTML encoding format", and change the first field of the table ztre Lines 5, 6, and 7 are defined as repeating areas, and the data is paging into table ztre. The results are shown in Figure 5-2-5:
Figure 5-2-5 Bind the data set Htre to the table ztre
(7) Open the home page index.aspx, select the dynamic text (Ztre.ZTNAME), create a hyperlink, link to hf.aspx, switch to the code view, and put the link Change the attribute to: hf.aspx?ztanw=. After dragging the field ZTID under the data set Ztre to the equal sign, the result is as shown in Figure 5-2-6:
Figure 5-2-6 Add dynamic hyperlinks in the code
(8) Save hf.aspx and index.asps, enter a few records into the corresponding HF table and YH table in Access, and browse index.asps in IE browser , click on the study note topic with reply, as shown in Figure 5-2-7:
Figure 5-2-7 Display of the reply page
(9) Then click any hyperlink in the data set navigation, the result is as shown in Figure 5-2-8:
Figure 5-2-8 The page results after clicking on the data set navigation
! All gone! This is the problem of data transfer between ASP.NET web pages. It must be modified as in Section 5.1.
(10) Switch to the code view and insert the code shown in the red circle in Figure 5-2-9 before the <html> tag.
Figure 5-2-9 Insert the page into hf.aspx to load the default function
(11) Find the code in the data set Ztre:
<Parameter Name="@ZTID" Value='<%# IIf((request.QueryString("ztanw ") <> Nothing), request.QueryString("ztanw"), "") %>' Type="Integer" />
Replace request.QueryString("ztanw") in the above code with session("ztanw"), The result code is modified to
<Parameter Name="@ZTID" Value='<%# IIf((session("ztanw")<> Nothing), session("ztanw"), "") %>' Type="Integer" />
(12) Find the code in the data set Hfre:
<Parameter Name="@ZTID" Value='<%# IIf((request.QueryString("ztanw") <> Nothing), request.QueryString("ztanw" ), "") %>' Type="Integer" />
Replace request.QueryString("ztanw") in the above code with session("ztanw"), and the resulting code is modified to
<Parameter Name="@ZTID" Value= '<%# IIf((session("ztanw")<> Nothing), session("ztanw"), "") %>' Type="Integer" />
(13) Save hf.aspx.