简体   繁体   English

关闭ASP.NET CSS友好适配器

[英]Turning off ASP.NET CSS Friendly Adapters

The CSS Friendly Control Adapters for ASP.NET are great for creating markup that is easy to style. 适用于ASP.NET的CSS友好控件适配器非常适合创建易于样式化的标记。 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. GridView适配器的一大好处是它可以生成THEAD,TBODY和TFOOT标记,这些标记允许您使用jQuery等库来做一些非常棒的事情 - 例如,用于客户端表排序的Tablesorter

The problem is that it seems to be a global on/off for the adapters through the CSSFriendlyAdapters.browser file. 问题是它似乎是通过CSSFriendlyAdapters.browser文件的适配器的全局开/关。 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? 如果我目前正在生产一系列GridView并且只想使用CSS友好适配器换一个新的?我该怎么办?

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. 1)扩展或修改GridView(可接受新标签)以输出THEAD和TBODY标签的方法。

2) A way to conditionally apply or disable CSS Friendly Control Adapters. 2)有条件地应用或禁用CSS友好控制适配器的方法。

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) 你需要子类化你想要使用的控件(在你的情况下是gridview,在我的情况下是radiobuttonlist)

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 然后让.browser文件引用您的自定义子类,而不是asp.net控件

eg 例如

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

CSS Friendly... CSS友好...

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. 如果您将AdapterEnabled =“false”显式添加到服务器端标记,则这些示例适配器将尝试使用ASP.NET框架的本机呈现来进行控制。 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. AdapterEnabled属性仅用于实验。

Source 资源

Alternatively, you can create a class that derives from GridView and overrides the RenderChildren method. 或者,您可以创建一个派生自GridView的类并重写RenderChildren方法。 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. 我没有看过如何在GridView中显示控件,以便为您提供这方面的任何想法。 Presumably, you'll just need to figure out which rows are header/foot and render / around them and around the others. 据推测,你只需要确定哪些行是标题/英尺,并在其周围和周围渲染/渲染。

I found a method of creating the THEAD and TBODY tags: 我找到了一种创建THEAD和TBODY标签的方法:

Source: Sortable GridView using jQuery's TableSorter 来源: 使用jQuery的TableSorter排序GridView

Bare Bones Details: 裸骨细节:

myGrid.UseAccessibleHeader = true;
myGrid.HeaderRow.TableSection = TableRowSection.TableHeader;
myGrid.FooterRow.TableSection = TableRowSection.TableFooter;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM