The GridView is a new web control in ASP.NET 2.0 and is an improvement of the old DataGrid. One of the biggest issues with the DataGrid was the lack of standard compliance and accessibility. This has been fixed in the new GridView along with a lot of other things as well.

When setting the property UseAccessibleHeader = true, it replaces the <td> elements of the header row with the correct <th> which means table header. It also adds the scope property of these header elements making them more accessible.

For some strange reason, there is no property for setting the <thead>, <tbody> and <tfoot> elements which are more important from an accessibility point of view. There is however an easy way of adding these elements in C# and VB.NET.

Let’s add a simple GridView to our page like this:

<asp:GridView runat="server" ID="gvFlowers" />

To add the extra elements, we need this simple method in the code-behind:

private void MakeAccessible(GridView grid)
{
 if (grid.Rows.Count > 0)
 {
  //This replaces <td> with <th> and adds the scope attribute
  grid.UseAccessibleHeader = true;

  //This will add the <thead> and <tbody> elements
  grid.HeaderRow.TableSection = TableRowSection.TableHeader;

  //This adds the <tfoot> element. Remove if you don't have a footer row
  grid.FooterRow.TableSection = TableRowSection.TableFooter;
 }
}

Then we just call the method from the Page_Load event like this:

protected void Page_Load(object sender, EventArgs e)
{
 //Add data to the GridView
 ...

 MakeAccessible(gvFlowers);
}

And this is the actual HTML that is generated:

<table cellspacing="0" rules="all" border="1" id="gvFlowers" style="border-collapse:collapse;">
        <thead>
            <tr>
                <th scope="col">Name</th><th scope="col">Height</th><th scope="col">Width</th>
            </tr>
        </thead><tbody>
            <tr>
                <td>tulip.jpg</td><td>30</td><td>420</td>
            </tr><tr>
                <td>daisy.jpg</td><td>32</td><td>481</td>
            </tr><tr>
                <td>rose.jpg</td><td>54</td><td>530</td>
            </tr>
        </tbody><tfoot>

        </tfoot>
</table>

It is not apparent that you have to dig into the header and footer rows and add a TableSection. This should be done automatically or at least be easy to set through a property at design time. I think it is an obvious mistake, but luckily for us, it is easy to fix if you know where to look.

For the past six months or so, I’ve been working on a really cool website in ASP.NET 2.0. As soon as the last bugs and design tweaks have been dealt with, we are releasing it to the world – we’re almost there.

Yesterday, the webmaster wanted to do some changes to the website himself. He knows a little HTML and has managed sites before - including the old version of the site we’re building. So, I gave him the FTP login information and he connected from Dreamweaver as he is used to. However, Dreamweaver do not understand ASP.NET 2.0 Master Pages and screwed everything up.

He knows Dreamweaver and feels comfortable using it, but he had to make the switch to Visual Web Developer Express (VWDE) in order to make it work and that didn’t please him. We finally connected using VWDE and all works fine. Or at least we thought it did…

A new problem that I hadn’t foreseen presented itself in the form of the complexity of the .aspx, .ascx and .cs files. For a person used to manage old ASP pages this turned out to be a nightmare. That’s because with the old ASP it was fairly easy to manage the different #include files and find the text you want to change, but in ASP.NET, the text could be located at various different location including in the C#/VB.NET code from another assembly or an embedded resource file.

I would imagine that this issue is shared throughout the community, but it was my first encounter with it.

Back in the days when ASP.NET 1.0 was released, Microsoft said that it was now possible for developers and designers to work together on the same project, because of the separation of HTML and the code-behind. In the light of the above mentioned issue, I do not see how this is possible unless the designer/webmaster knows his way around assemblies, resource files and C#/VB.NET, which then would make him a developer and not a webmaster.

Also, the webmaster uses the VWDE designer and that is something I NEVER do, so I didn’t make an effort to make design time databinding and stuff like that, which makes the page look miserable in the designer.

It is easier to manage an ASP website for non-developers and that’s such a shame for, let’s be honest, it sucked.

The more you separate code to user- and server controls the more difficult it becomes to manage it. So, the next question would naturally be: If the website is to be managed by a non-developer, should you avoid the separation?

A solution could be to change the password for the FTP site, so the webmaster won’t get access, but that will only lead to extra work for myself, so that doesn’t count as a solution.