Danh mục

Make a Generic Search Form in an ASP.NET

Số trang: 12      Loại file: pdf      Dung lượng: 43.65 KB      Lượt xem: 13      Lượt tải: 0    
tailieu_vip

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

8,8 Thực hiện một Generic Mẫu tìm kiếm trong một ASP.NET Web Application Bài viết này sẽ chỉ cho bạn làm thế nào để thêm một Web Form tìm kiếm độc đáo để ứng dụng Web của bạn mà có thể được thiết lập bằng cách sử dụng các biến session và sử dụng cho các bảng khác nhau.
Nội dung trích xuất từ tài liệu:
Make a Generic Search Form in an ASP.NET 8.8 Make a Generic Search Form in an ASP.NET Web ApplicationThis tutorial will show you how to add a unique search Web Form to your Webapplication that can be set up using session variables and used for various tables.Creating search forms for Web applications is pretty common. You would like to be ableto use the same Web Form for different tables in the same application.This How-To will demonstrate using the same Web Form for searching various tables,taking advantage of the Session object.TechniqueThis How-To will use the Session object with a Web Form, something that has been donethroughout the book. You will see a good example of using the Session object to passvalues-in this case, the record source, the key search field, and the display search field-tothe search form. Finally, the return value will be passed back to the calling Web Formusing the Session object.One new control that is used in this How-To is the Panel control. It will be used to groupthe controls on the search Web Form. The Panel control will be used simply by throwingcontrols into it and letting it control the layout.You will see the paging used with the DataGrid control as well.StepsOpen and run the VB.NET -Chapter 8 solution. From the main Web Form, click on thehyperlink with the caption How-To 8.8: Make a Generic Search Form Using a WebForm. This page is a simple one that contains text boxes for the Customer table inNorthwind (see Figure 8.15). Figure 8.15. This Customers page is a common one used to demonstrate calling the search form.Click on the Search button to open the search page, and then click on the button labeledB. You will see the DataGrid object displayed in the bottom of the form filled with theCompanyID and CompanyName fields of the Customer table, which begin with B (seeFigure 8.16). Figure 8.16. This form can be used for searching within any of the tables in your databases.Click the Select button for one of the customers who is displayed in the grid, and thenclick Accept. The customer page will be displayed, and the fields will be filled in with thedata from the chosen record. 1. Create a Web Form. Then place the controls shown in Figure 8.16 of the form calling the search form, with the properties set forth in Table 8.10. Table 8.10. Label, TextBox, and Command Button Controls Property Settings for the Calling Form Object Property Setting DOCUMENT bgColor buttonface Label Caption Customer ID Label Caption Company Name Label Caption Contact Label Caption Contact Title Label Caption Address Label Caption CityLabel Caption RegionLabel Caption CountryLabel Caption PhoneLabel Caption FaxTextBox Name txtCustomerIDTextBox Name txtCompanyNameTextBox Name txtContactNameTextBox Name txtContactTitleTextBox Name txtAddressTextBox Name txtCityTextBox Name txtRegionTextBox Name txtPostalCodeTextBox Name txtCountryTextBox Name txtPhoneTextBox Name txtFaxButton Name btnSearch Caption &Search2. On btnSearch, add the code in Listing 8.45 to the Click event. This sets up the search Web Form as far as telling it what it needs to know, including how to get back to this page, which is the calling page. The search page, in this case wfrmHowTo8_8b.aspx, is then opened. Listing 8.45 frmHowTo8_8a.vb: Storing Values to the Session Object for Use on Another Page Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click Session.Item(SearchRecordSource) = Customers Session.Item(SearchField) = CompanyName Session.Item(KeyField) = CustomerID Session.Item(CallingPage) = wfrmHowTo8_8a.aspx Server.Transfer(wfrmHowTo8_8b.aspx) End Sub3. Add the code in Listing 8.46 to the Load event of the Web Form. If the Session object has an entry for ResultValue, then the LoadIndividual r ...

Tài liệu được xem nhiều: