I've just converted my application to use the GridView CSS adapter, and I've noticed that it doesn't distinguish between Item styles and header styles when rendering the cells. Thus if you have a column like this...
<asp:BoundField HeaderText="Monthly" DataField="Monthly" ItemStyle-CssClass="CellRight" />
... it will apply the style "CellRight" to both the item cells and the row header, which is not what I wanted.
I've fixed the GridView Adapter to allow this to work. I've included my modified WriteRows function below:
1 private void WriteRows(HtmlTextWriter writer, GridView gridView, GridViewRowCollection rows, string tableSection) {
2 if (rows.Count > 0) {
3 writer.WriteLine();
4 writer.WriteBeginTag(tableSection);
5 writer.Write(HtmlTextWriter.TagRightChar);
6 writer.Indent++;
7
8 foreach (GridViewRow row in rows) {
9 writer.WriteLine();
10 writer.WriteBeginTag("tr");
11
12 string className = GetRowClass(gridView, row);
13 if (!String.IsNullOrEmpty(className)) {
14 writer.WriteAttribute("class", className);
15 }
16
17 // Uncomment the following block of code if you want to add arbitrary attributes.
18 /*
19 foreach (string key in row.Attributes.Keys)
20 {
21 writer.WriteAttribute(key, row.Attributes[key]);
22 }
23 */
24
25 writer.Write(HtmlTextWriter.TagRightChar);
26 writer.Indent++;
27
28 foreach (TableCell cell in row.Cells) {
29 DataControlFieldCell fieldCell = cell as DataControlFieldCell;
30 if ((fieldCell != null) && (fieldCell.ContainingField != null)) {
31 DataControlField field = fieldCell.ContainingField;
32 if (!field.Visible) {
33 cell.Visible = false;
34 }
35
36 if (row.RowType == DataControlRowType.Header) {
37 if ((field.HeaderStyle != null) && (!String.IsNullOrEmpty(field.HeaderStyle.CssClass))) {
38 if (!String.IsNullOrEmpty(cell.CssClass)) {
39 cell.CssClass += " ";
40 }
41 cell.CssClass += field.HeaderStyle.CssClass;
42 }
43
44 } else if (row.RowType == DataControlRowType.DataRow) {
45 if ((field.ItemStyle != null) && (!String.IsNullOrEmpty(field.ItemStyle.CssClass))) {
46 if (!String.IsNullOrEmpty(cell.CssClass)) {
47 cell.CssClass += " ";
48 }
49 cell.CssClass += field.ItemStyle.CssClass;
50 }
51
52 } else if (row.RowType == DataControlRowType.Footer) {
53 if ((field.FooterStyle != null) && (!String.IsNullOrEmpty(field.FooterStyle.CssClass))) {
54 if (!String.IsNullOrEmpty(cell.CssClass)) {
55 cell.CssClass += " ";
56 }
57 cell.CssClass += field.FooterStyle.CssClass;
58 }
59
60 }
61
62 }
63
64 writer.WriteLine();
65 cell.RenderControl(writer);
66 }
67
68 writer.Indent--;
69 writer.WriteLine();
70 writer.WriteEndTag("tr");
71 }
72
73 writer.Indent--;
74 writer.WriteLine();
75 writer.WriteEndTag(tableSection);
76 }
77 }