advanced topics on using ado.net in asp.net data binding
TRANSCRIPT
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
1/25
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
2/25
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
3/25
3
DataGridDataGrid -- Multiple Item SelectionMultiple Item Selection
Functionality: Users select multiple rows byFunctionality: Users select multiple rows bychecking the check box for each row, andchecking the check box for each row, andthen perform an action on the selectedthen perform an action on the selected
items.items.
Add a template column to the DataGrid, putAdd a template column to the DataGrid, puta CheckBox control in its ItemTemplate.a CheckBox control in its ItemTemplate.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
4/25
4
DataGridDataGrid -- Multiple Item SelectionMultiple Item Selection (2)(2)
In the code behind, walk through eachIn the code behind, walk through eachDataGrid item to see if the check box isDataGrid item to see if the check box ischecked; if checked, perform the action.checked; if checked, perform the action.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
5/25
5
DataGridDataGrid -- Multiple Item EditingMultiple Item Editing
FunctionalityFunctionality Data is displayed in editable controls byData is displayed in editable controls by
default.default.
Users make changes in multiple items andUsers make changes in multiple items andthen click a button to commit all changesthen click a button to commit all changesat once.at once.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
6/25
6
DataGridDataGrid -- Multiple Item EditingMultiple Item Editing (2)(2)
Create template columns for editable data.Create template columns for editable data.
Add editable controls in the ItemTemplate.Add editable controls in the ItemTemplate.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
7/25
7
DataGridDataGrid -- Multiple Item EditingMultiple Item Editing (3)(3)
Updating is slightly different in the codeUpdating is slightly different in the codebehind.behind.
When the user clicks the Update button,When the user clicks the Update button,there is no way to keep track of whichthere is no way to keep track of whichcolumns of which rows have been modified.columns of which rows have been modified.
Need to go through each DataGrid item,Need to go through each DataGrid item,extract values from all editable controls, andextract values from all editable controls, andmake updates for all the rows.make updates for all the rows.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
8/25
8
DataGridDataGrid -- Multiple Item EditingMultiple Item Editing (4)(4)
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
9/25
9
DataGridDataGrid -- Summary RowsSummary Rows
Functionality: DataGrid contains summaryFunctionality: DataGrid contains summaryrows to display partial totals of groupedrows to display partial totals of groupedcolumns.columns.
The sample is based on theThe sample is based on the
Northwind MicrosoftNorthwind Microsoft SQLSQLServerServer database. Thedatabase. TheDataGrid lists all the ordersDataGrid lists all the ordersthat each customer hasthat each customer hasissued in year 1998.issued in year 1998.
For each customer, aFor each customer, asummary row displays thesummary row displays thetotal amount of orders.total amount of orders.An extra row summarizes theAn extra row summarizes thegrand total for all customers.grand total for all customers.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
10/25
10
DataGridDataGrid -- Summary RowsSummary Rows (2)(2)
DataGrid doesnt have the feature forDataGrid doesnt have the feature forsummary; you must insert summary rowssummary; you must insert summary rowsdirectly into the data source before attachingdirectly into the data source before attachingthe data to the grid.the data to the grid.
When rows are being drawn, distinguishWhen rows are being drawn, distinguishsummary rows from ordinary rows, andsummary rows from ordinary rows, andrender the former with different layout andrender the former with different layout andstyle.style.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
11/25
11
DataGridDataGrid -- Summary RowsSummary Rows (3)(3)
The GROUP BY clause of the SELECT statement in TThe GROUP BY clause of the SELECT statement in T--SQLSQLprovides the WITH ROLLUP extension that adds predefinedprovides the WITH ROLLUP extension that adds predefinedsummary rows to the result set.summary rows to the result set.
GROUPING is the TGROUPING is the T--SQL aggregate function that works inSQL aggregate function that works inconjunction with ROLLUP. The use of the GROUPING operatorconjunction with ROLLUP. The use of the GROUPING operatorcauses a new column to be added to the result set. This columncauses a new column to be added to the result set. This columncontains a value of 1 if it is grouped by the ROLLUP operator.contains a value of 1 if it is grouped by the ROLLUP operator.Otherwise, the column takes a value of 0.Otherwise, the column takes a value of 0.
By using a CASE..WHEN..END statement you can merge this newBy using a CASE..WHEN..END statement you can merge this new
column with the grouping column.column with the grouping column.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
12/25
12
DataGridDataGrid -- Summary RowsSummary Rows (4)(4)
The result of the query on the previous slide.The result of the query on the previous slide.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
13/25
13
DataGridDataGrid -- Summary RowsSummary Rows (5)(5)
The DataGrid declaration in HTML view.The DataGrid declaration in HTML view.
In the ItemCreated event handler, detect eachIn the ItemCreated event handler, detect eachsummary row, and modify its layout and style.summary row, and modify its layout and style.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
14/25
14
DataGridDataGrid -- Summary RowsSummary Rows (6)(6)
The item text is set only during theThe item text is set only during theOnItemDataBound event.OnItemDataBound event.
Modifying the text in summary rows must beModifying the text in summary rows must bedone in the OnItemDataBound eventdone in the OnItemDataBound event
handler.handler.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
15/25
15
DataGridDataGrid -- Summary RowsSummary Rows (7)(7)
The final DataGrid.The final DataGrid.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
16/25
16
DataGridDataGrid -- Master/Detail PageMaster/Detail Page
Functionality: Users select an item in theFunctionality: Users select an item in themaster DataGrid, and the details will bemaster DataGrid, and the details will bedisplayed in another DataGrid.displayed in another DataGrid.
Load two tables in the DataSet and create aLoad two tables in the DataSet and create aDataRelation between them.DataRelation between them.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
17/25
17
DataGridDataGrid -- Master/Detail PageMaster/Detail Page (2)(2)
The SelectedIndexChanged event is fired onThe SelectedIndexChanged event is fired onselecting an item in the master DataGrid.selecting an item in the master DataGrid.
In its event handler, get the correspondingIn its event handler, get the correspondingDataRows through the DataRelation, and bindDataRows through the DataRelation, and bind
the rows to the detail DataGrid.the rows to the detail DataGrid.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
18/25
18
Web Data Access StrategyWeb Data Access StrategyDataReaderDataReader oror DataSetDataSet
DataReaderDataReader
Slightly better performance and memorySlightly better performance and memoryusageusage
Data object, by default, is discarded withData object, by default, is discarded witheach round tripeach round tripusing DataAdapter forusing DataAdapter fordata binding is usually recommendeddata binding is usually recommended
Reasons for using DataSetReasons for using DataSet
Working with related tablesWorking with related tables
Exchanging data with other processesExchanging data with other processes
Working with a static set of recordsWorking with a static set of records
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
19/25
19
Web Data Access StrategyWeb Data Access StrategyCache DataSet or Reload DataSetCache DataSet or Reload DataSet
Caching DataSetCaching DataSet
Pro: saves trips to the data source.Pro: saves trips to the data source.
Con: consumes memory between roundCon: consumes memory between round
trips; can get out of sync with the datatrips; can get out of sync with the datasource.source.
Scenarios for reloading DataSetScenarios for reloading DataSet
Paging through data: reload the DataSetPaging through data: reload the DataSetto get the next set of records to display.to get the next set of records to display.
Working with very volatile data source.Working with very volatile data source.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
20/25
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
21/25
21
Web Data Access StrategyWeb Data Access StrategyCache on Client or on ServerCache on Client or on Server(2)(2)
Caching on the server: Save the datasetCaching on the server: Save the datasetin Session state, Application state, orin Session state, Application state, orusing a cache.using a cache.
Session is scoped to the current browserSession is scoped to the current browsersession.session.
Application: global storage accessibleApplication: global storage accessiblefrom all pages in the Web application.from all pages in the Web application.
Cache: threadCache: thread--safe application levelsafe application levelglobal storage. Cache manager willglobal storage. Cache manager willremove the leastremove the least--used items if the serverused items if the serverneeds memory or if cached data expires.needs memory or if cached data expires.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
22/25
22
Web Data Access StrategyWeb Data Access StrategyCache on Client or on ServerCache on Client or on Server(3)(3)
Example for using caching sessionExample for using caching session
To store the DataSet in the cache:To store the DataSet in the cache:
To get the DataSet back:To get the DataSet back:
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
23/25
23
Web Data Access StrategyWeb Data Access StrategySave DataSet in XML FileSave DataSet in XML File
Doesnt take up server or client resourcesDoesnt take up server or client resources
Takes a relatively long time to serialize andTakes a relatively long time to serialize anddeserialize data.deserialize data.
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
24/25
24
Additional ResourcesAdditional Resources
Knowledge Base articlesKnowledge Base articles Q313481Q313481 INFO: Roadmap for Web Forms DataINFO: Roadmap for Web Forms Data
BindingBinding
Q307860Q307860 INFO: ASP.NET Data BindingINFO: ASP.NET Data Binding
OverviewOverview Q305140Q305140 INFO: ASP.NET RoadmapINFO: ASP.NET Roadmap
Q313590Q313590 INFO: Roadmap for ADO.NETINFO: Roadmap for ADO.NET
Other linksOther links
Support WebCast: Microsoft ASP.NET DataGridSupport WebCast: Microsoft ASP.NET DataGridWeb Server ControlWeb Server Control
Support WebCast: Data Binding in ASP.NET WebSupport WebCast: Data Binding in ASP.NET WebFormsForms
-
8/7/2019 Advanced Topics on Using ADO.NET in ASP.NET Data Binding
25/25
25