Working with Data in ASP.NET 2.0 - Efficiently Paging Through Large Amounts of Data
As we discussed in the preceding tutorial, paging can be implemented in one of two ways:
- Default Paging – can be implemented by simply checking the Enable Paging option in the data Web control’’s smart tag? however, whenever viewing a page of data, the ObjectDataSource retrieves all of the records, even though only a subset of them are displayed in the page
- Custom Paging – improves the performance of default paging by retrieving only those records from the database that need to be displayed for the particular page of data requested by the user? however, custom paging involves a bit more effort to implement than default paging
Read more
Master Pages Control ID Naming in Content Pages Introduction
All ASP.NET server controls include an ID property that uniquely identifies the control and is the means by which the control is programmatically accessed in the code-behind class. Similarly, the elements in an HTML document may include an id attribute that uniquely identifies the element; these id values are often used in client-side script to programmatically reference a particular HTML element. Given this, you may assume that when an ASP.NET server control is rendered into HTML, its ID value is used as the id value of the rendered HTML element. This is not necessarily the case because in certain circumstances a single control with a single ID value may appear multiple times in the rendered markup. Consider a GridView control that includes a TemplateField with a Label Web control with an ID value of ProductName. When the GridView is bound to its data source at runtime, this Label is repeated once for every GridView row. Each rendered Label needs a unique id value.
Read more
Working with Data in ASP.NET 2.0 Handling BLL and DAL Level Exceptions in an ASP.NET Page
Working with data from an ASP.NET web application using a tiered application architecture involves the following three general steps:
1. Determine what method of the Business Logic Layer needs to be invoked and what parameter values to pass it. The parameter values can be hard coded, programmatically assigned, or inputs entered by the user.
2. Invoke the method.
3. Process the results. When calling a BLL method that returns data, this may involve binding the data to a data Web control. For BLL methods that modify data, this may include performing some action based on a return value or gracefully handling any exception that arose in Step 2.
Read more
Working with Data in ASP.NET 2.0 - Handling BLL and DALLevel Exceptions
In the Overview of Editing and Deleting Data in the DataList tutorial, we created a DataList that offered simple editing and deleting capabilities. While fully functional, it was hardly userfriendly, as any error that occurred during the editing or deleting process resulted in an unhandled exception. For example, omitting the product’s name or, when editing a product, entering a price value of “Very affordable!”, throws an exception. Since this exception is not caught in code, it bubbles up to the ASP.NET runtime, which then displays the exception’s details in the web page. As we saw in the Handling BLLand DALLevel Exceptions in an ASP.NET Page tutorial, if an exception is raised from the depths of the Business Logic or Data Access Layers, the exception details are returned to the ObjectDataSource and then to the GridView. We saw how to gracefully handle these exceptions by creating Updated or RowUpdated event handlers for the ObjectDataSource or GridView, checking for an exception, and then indicating that the exception was handled.
Read more
Working with Data in ASP.NET 2.0 Displaying Data with the DataList and Repeater Controls
In all of the examples throughout the past 28 tutorials, if we needed to display multiple records from a data source we turned to the GridView control. The GridView renders a row for each record in the data source, displaying the record’s data fields in columns. While the GridView makes it a snap to display, page through, sort, edit, and delete data, its appearance is a bit boxy. Moreover, the markup responsible for the GridView’s structure is fixed - it includes an HTML with a table row () for each record and a table cell () for each field. To provide a greater degree of customization in the appearance and rendered markup when displaying multiple records, ASP.NET 2.0 offers the DataList and Repeater controls (both of which were also available in ASP.NET version 1.x). The DataList and Repeater controls render their content using templates rather than BoundFields, CheckBoxFields, ButtonFields, and so on. Like the GridView, the DataList renders as an HTML , but allows for multiple data source records to be displayed per table row. The Repeater, on the other hand, renders no additional markup than what you explicitly specify, and is an ideal candidate when you need precise control over the markup emitted.
Read more