views:

1230

answers:

3

The CSS Friendly Control Adapters for ASP.NET are great for creating markup that is easy to style. A big benefit of the GridView adapter is that it generates THEAD, TBODY, and TFOOT tags, which allow you to do some really great things with libraries like jQuery - for instance, Tablesorter for client-side table sorting.

The problem is that it seems to be a global on/off for the adapters through the CSSFriendlyAdapters.browser file. What do I do if I already have a slew of GridViews currently in production and only want to use the CSS Friendly Adapters for a new one?

So I would be interested in two types of solutions:

1) A way to extend or modify GridView (a new tag is acceptable) to output THEAD and TBODY tags.

2) A way to conditionally apply or disable CSS Friendly Control Adapters.

A: 

CSS Friendly...

Disabling Adapters

If you explicitly add AdapterEnabled="false" to your server-side tag, these sample adapters will attempt to use the ASP.NET framework's native rendering for the control. Beware: this is not supported and often does not work well. Fundamentally, the framework does not support disabling adapters on a per control basis. The AdapterEnabled attribute is only intended to be used experimentally.

Source

Alternatively, you can create a class that derives from GridView and overrides the RenderChildren method. It may take some experimentation to figure out how to make this work. I haven't looked at how the controls are presented in the GridView to give you any ideas in this regard. Presumably, you'll just need to figure out which rows are header/foot and render / around them and around the others.

tvanfosson
Disabling the adapters isn't a very elegant solution, as it would require touching every existing grid. It would be much better to have a solution where the adapter can be conditionally enabled.Overriding RenderChildren method seems like too much work, and too error-prone for real use.
David
A: 

I found a method of creating the THEAD and TBODY tags:

Source: Sortable GridView using jQuery's TableSorter

Bare Bones Details:

myGrid.UseAccessibleHeader = true;
myGrid.HeaderRow.TableSection = TableRowSection.TableHeader;
myGrid.FooterRow.TableSection = TableRowSection.TableFooter;
David
+3  A: 

Hi

I just did something similar to this after doing a little research

you need to subclass the control you want to use (gridview in your case, radiobuttonlist in my case)

public class UlRadioButtonList : RadioButtonList
    {
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            // Call the base RenderContents method.
            base.Render(writer);
        }
    }

Then just have the .browser file refer to your custom subclass, instead of the asp.net control

e.g.

<browsers>
  <browser refID="Default">
    <controlAdapters>
      <adapter controlType="FM.Web.Source.WebControls.UlRadioButtonList" adapterType="FM.Web.Source.ControlAdapters.RadioButtonListAdapter" />
    </controlAdapters>
  </browser>
</browsers>
Christo Fur