Use a Single Web Form to Update Multiple Lookup Tables
Số trang: 19
Loại file: pdf
Dung lượng: 45.16 KB
Lượt xem: 9
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Sử dụng mẫu đơn Web để cập nhật nhiều Lookup Bàn Như với hướng dẫn thứ hai (8,2), ví dụ này sẽ cho bạn thấy làm thế nào để cập nhật các bảng tra cứu nhiều, thời gian này bằng cách sử dụng một mẫu Web.
Nội dung trích xuất từ tài liệu:
Use a Single Web Form to Update Multiple Lookup Tables 8.6 Use a Single Web Form to Update Multiple Lookup TablesAs with the second tutorial(8.2), this example will show you how to update multiplelookup tables-this time using a Web Form.Creating a Web Form for viewing multiple lookup tables would take about the same ifnot less code than performing the same task using the Windows Form. Updating, adding,and deleting data takes a bit more work, though. This How-To will show you how toaccomplish this task by using the DataGrid control and show you how to take advantageof Session variables and paging within the data grid when youre manipulating data.TechniqueThe DataGrid control is a powerful control, as you saw in Chapter 5, Working with Dataon Web Forms, but when programming in Web Forms, it takes some getting used to.Because the Web Forms are stateless, you need to keep reminding the data grid what it isbound to.Also, even though you declare a variable at the module level behind the form, you willnotice that whenever the form goes back to the server for information, you lose the valuesof your variables. The workaround for this is the use of the Session object.Note A full discussion of State management in .NET and the various options is presented in Chapter 5. This also includes how to use the options for the data grid manipulation portion of this How-To.The other major issue with this How-To is managing the paging of the DataGrid control,covered in Chapter 4. You will quickly learn the steps of creating the Web Form thatallows users to update Lookup tables.StepsOpen and run the VB.NET -Chapter 8 solution. From the main Web Form, click on thehyperlink with the caption How-To 8.6: Use a Single Web Form for Updating MultipleLookup Tables. Click on the first choice, Categories, in the list box labeled Lookup Tableto Edit. The data grid will then appear. The grid will be filled in with the data of the tableyou chose. Your page will then look like the page displayed in Figure 8.9. Figure 8.9. On this page, you can add, edit, and delete information for all your simple lookup tables.You can now add data into the data grid by clicking on the Add New button, locatedunder the Error box. When you click on the Add New button, an entry is added to thedata grid, and you are placed in Edit mode, shown in Figure 8.10. Figure 8.10. Adding new data to your lookup tables using the DataGrid control.After entering the data into the fields, you will click Update. The values are then savedback to the server. If you dont want to save the new entry, click the Cancel button, andthe data grid makes the entry disappear.TipYou will notice that the look of the columns is a little congested and changes when yougo to edit the data. You can avoid this by creating and using templates with the data grid.Of course, if you are using templates with the data grid, you have to change the templatebased on the lookup table you were using.Tip You will also notice that the CategoryID field has been disabled and cant be edited. This is through the use of a method, FillSchema, which fills data table with schema information from the record source. In this case, FillSchema passed on the information that the CategoryID was an AutoIncrement field, and the data grid was smart enough to handle it.When you click on the Edit button, the page will look similar to Figure 8.10, except thatdata already will be present in the fields. When you click Delete, the entry is deleted.Any errors that might occur, such as from data integrity errors, will appear in the text boxlabeled Errors. If you try to delete a current category and Products uses that category, forexample, then SQL Server causes an error to occur, and the page reports the errorbecause of code created. 1. Create a Web Form. Then place the controls shown in Figure 8.9 with the properties shown in Table 8.8. Table 8.8. Label, TextBox, ListBox, and Command Button Control Property Settings Object Property Setting DOCUMENT bgColor buttonface Label Name Label1 Text Lookup Table to Edit: ListBox Name lstLookupTables AutoPostback True Label Name Label2 Text Lookup Table Data: DataGrid Name dgLookupData AllowPaging True PageSize 5 Label ...
Nội dung trích xuất từ tài liệu:
Use a Single Web Form to Update Multiple Lookup Tables 8.6 Use a Single Web Form to Update Multiple Lookup TablesAs with the second tutorial(8.2), this example will show you how to update multiplelookup tables-this time using a Web Form.Creating a Web Form for viewing multiple lookup tables would take about the same ifnot less code than performing the same task using the Windows Form. Updating, adding,and deleting data takes a bit more work, though. This How-To will show you how toaccomplish this task by using the DataGrid control and show you how to take advantageof Session variables and paging within the data grid when youre manipulating data.TechniqueThe DataGrid control is a powerful control, as you saw in Chapter 5, Working with Dataon Web Forms, but when programming in Web Forms, it takes some getting used to.Because the Web Forms are stateless, you need to keep reminding the data grid what it isbound to.Also, even though you declare a variable at the module level behind the form, you willnotice that whenever the form goes back to the server for information, you lose the valuesof your variables. The workaround for this is the use of the Session object.Note A full discussion of State management in .NET and the various options is presented in Chapter 5. This also includes how to use the options for the data grid manipulation portion of this How-To.The other major issue with this How-To is managing the paging of the DataGrid control,covered in Chapter 4. You will quickly learn the steps of creating the Web Form thatallows users to update Lookup tables.StepsOpen and run the VB.NET -Chapter 8 solution. From the main Web Form, click on thehyperlink with the caption How-To 8.6: Use a Single Web Form for Updating MultipleLookup Tables. Click on the first choice, Categories, in the list box labeled Lookup Tableto Edit. The data grid will then appear. The grid will be filled in with the data of the tableyou chose. Your page will then look like the page displayed in Figure 8.9. Figure 8.9. On this page, you can add, edit, and delete information for all your simple lookup tables.You can now add data into the data grid by clicking on the Add New button, locatedunder the Error box. When you click on the Add New button, an entry is added to thedata grid, and you are placed in Edit mode, shown in Figure 8.10. Figure 8.10. Adding new data to your lookup tables using the DataGrid control.After entering the data into the fields, you will click Update. The values are then savedback to the server. If you dont want to save the new entry, click the Cancel button, andthe data grid makes the entry disappear.TipYou will notice that the look of the columns is a little congested and changes when yougo to edit the data. You can avoid this by creating and using templates with the data grid.Of course, if you are using templates with the data grid, you have to change the templatebased on the lookup table you were using.Tip You will also notice that the CategoryID field has been disabled and cant be edited. This is through the use of a method, FillSchema, which fills data table with schema information from the record source. In this case, FillSchema passed on the information that the CategoryID was an AutoIncrement field, and the data grid was smart enough to handle it.When you click on the Edit button, the page will look similar to Figure 8.10, except thatdata already will be present in the fields. When you click Delete, the entry is deleted.Any errors that might occur, such as from data integrity errors, will appear in the text boxlabeled Errors. If you try to delete a current category and Products uses that category, forexample, then SQL Server causes an error to occur, and the page reports the errorbecause of code created. 1. Create a Web Form. Then place the controls shown in Figure 8.9 with the properties shown in Table 8.8. Table 8.8. Label, TextBox, ListBox, and Command Button Control Property Settings Object Property Setting DOCUMENT bgColor buttonface Label Name Label1 Text Lookup Table to Edit: ListBox Name lstLookupTables AutoPostback True Label Name Label2 Text Lookup Table Data: DataGrid Name dgLookupData AllowPaging True PageSize 5 Label ...
Tìm kiếm theo từ khóa liên quan:
công nghệ máy tính phần mềm kĩ thuật lập trình dữ liệu Use a Single WebTài liệu liên quan:
-
6 trang 192 0 0
-
Giáo trình Cấu trúc máy tính - CĐN Công nghiệp Hà Nội
124 trang 49 0 0 -
Đề thi trắc nghiệm quản trị mạng
41 trang 47 0 0 -
24 trang 43 0 0
-
Bài giảng Quản trị dự án phần mềm: Bài 1 - Đào Kiến Quốc
22 trang 41 0 0 -
4 trang 41 0 0
-
Các Chủ Đề Tiến Bộ Trong C# part
8 trang 39 0 0 -
4 trang 37 0 0
-
Create a New SQL Server Database from Within Visual Studio .NET
3 trang 32 0 0 -
7 trang 31 0 0
-
Truyền dẫn thông tin - Chương 5
11 trang 30 0 0 -
40 trang 30 0 0
-
Using the SQL Server FOR XML Clause
12 trang 29 0 0 -
Cấu trúc dữ liệu và giải thuật (phần 15)
10 trang 29 0 0 -
Các Chủ Đề Tiến Bộ Trong C# part 1
19 trang 29 0 0 -
Phần tích thiết kế giải thuật (phần 1)
11 trang 28 0 0 -
Truyền dẫn thông tin - Chương 3
19 trang 28 0 0 -
5 trang 27 0 0
-
Lập trình trong môi trường .NET part 1
26 trang 27 0 0 -
3 trang 27 0 0