tailieunhanh - Synchronizing Master-Detail Web Forms DataGrids

[ Team LiB ] Recipe Synchronizing Master-Detail Web Forms DataGrids Problem You need to create a master-detail pair of DataGrid controls and synchronize them so that when you select a record in the master, the child grid is updated with the corresponding records. Solution Fill a DataSet with results from both tables | Team LiB Recipe Synchronizing Master-Detail Web Forms DataGrids Problem You need to create a master-detail pair of DataGrid controls and synchronize them so that when you select a record in the master the child grid is updated with the corresponding records. Solution Fill a DataSet with results from both tables and create the necessary relations before binding the DataGrid to the DataSet. The code for the Web Forms page is shown in Example 7-11. Example 7-11. File form id ADOCookbookCS0706 method post runat server asp HyperLink id HyperLink1 style Z-INDEX 101 LEFT 16px POSITION absolute TOP 24px runat server NavigateUrl Main Menu asp HyperLink br br br asp DataGrid id ordersDataGrid runat server PageSize 5 AllowPaging True SelectedItemStyle BackColor 80FF80 SelectedItemStyle AlternatingItemStyle BackColor FFFF99 AlternatingItemStyle Columns asp ButtonColumn Text Detail CommandName Select asp ButtonColumn Columns asp DataGrid br br asp DataGrid id orderDetailsDataGrid runat server PageSize 2 AllowPaging True Width 200px AlternatingItemStyle BackColor FFFF99 AlternatingItemStyle asp DataGrid form The code-behind file contains four event handlers and a single method Calls the CreateDataSource method and binds the parent data to the parent Web Forms DataGrid if the page is being loaded for the first time. CreateDataSource This method fills a DataSet with the Orders table and the Order Details table from the Northwind sample database creates a relation between the tables and stores the DataSet to a Session variable to cache the data source for both parent and child DataGrid objects. Orders Gets the cached data from the Session variable. If a row is selected in the Orders data grid a DataView is created containing Order Details for the row selected in the Orders data grid and bound to the Order Details data grid otherwise the Order Details data grid is cleared. Orders .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.