Cleaning up the GridView’s EmptyDataTemplate (damn those tables!)

A project I’ve been working on makes frequent use of the ASP.Net GridView. However, as many people know, the GridView has one glaring issue: It wraps your <EmptyDataTemplate> in an HTML table — something that I don’t want, for two reasons:

My empty data template does not consist of tabular data.
My stylesheet has a default style for tables — a style that I don’t want applied to my empty data template.

One solution is to use the CSS Friendly Adapters for ASP.Net, which potentially solves both prolems, but that will bring in potential breaking changes to my GridView controls. I don’t have time for that (yet).

The solution I came up with is to do two things:

Create a new CSS class that removes table formatting (borders, backgrounds, padding, margins, etc.). This class will be applied to the GridView only when it has no data.
Add a line of code in the OnPreRender() method for each web page or control that . . .

→ Read More: Cleaning up the GridView’s EmptyDataTemplate (damn those tables!)

CSS Friendly ASP.Net Adapter updates to GridView, DetailsView, and FormView

If you’ve used the CSS Friendly ASP.Net Control Adapters in the past, you may want to check out change set 9278, which included a number of improvements to the GridView, DetailsView, and FormView controls.

From the check-in notes:

- Major rewrites of GridView, DetailsView, and FormView walkthroughs
- FormView and DetailsView now use PagerTemplate when it exists
- FormView, DetailsView, and GridView properly position pager based on PagerPosition and Visibile properties
- Implemented GridView’s DataControlRowType.Pager instead of hard-coded CSS class (non-breaking change)

The new test “walkthru” pages are quite useful. You can now set the control options and see the results of the change immediately without having to modify the code in the ASPX file. Implementing the test pages this way made it much easier to evaluate if the control adapters were doing what they were supposed to do.

. . .

→ Read More: CSS Friendly ASP.Net Adapter updates to GridView, DetailsView, and FormView