vb.net 如何在 gridview 中为 thead 元素设置类?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18633793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:56:44  来源:igfitidea点击:

How to set class for thead element in a gridview?

asp.netvb.netgridview

提问by lawphotog

I am trying to set THEADClass for GridView and I came as close as having a Theadelement without Class property and have class name I want to tr element. The reason is because PDF generator will look for a thead class name and generate table header on each page. PDF generator has problem rendering javascript sometimes so I prefer pure html and css on the page.

我正在尝试THEAD为 GridView设置Class 并且我几乎拥有一个Thead没有 Class 属性的元素,并且具有我想要 tr 元素的类名。原因是因为 PDF 生成器会在每一页上寻找一个 thead 类名并生成表头。PDF 生成器有时在渲染 javascript 时会出现问题,所以我更喜欢页面上的纯 html 和 css。

Code behind apart from databind.

除了数据绑定之外的代码。

GridView1.HeaderRow.TableSection = TableRowSection.TableHeader

Aspx

ASPX

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" HeaderStyle-CssClass="table-header-group">
<Columns>
    <asp:BoundField DataField="Forename" HeaderText="Forename" ItemStyle-Width="150" ItemStyle-CssClass="iClass" />
    <asp:BoundField DataField="Surname" HeaderText="Surname" ItemStyle-Width="150" ItemStyle-CssClass="iClass" />
</Columns>
</asp:GridView>

Generated HTML

生成的 HTML

<table class="gvPrinting" cellspacing="0" rules="all" border="1" id="GridView1" style="border-collapse:collapse;">
    <thead>
        <tr class="table-header-group">
            <th scope="col">Forename</th><th scope="col">Surname</th><th scope="col">DOB</th><th scope="col">Session Name</th><th scope="col">Password</th>
        </tr>
    </thead><tbody>
        <tr>
            <td colspan="5">+++</td>
        </tr><tr>

What I want is:

我想要的是:

     <thead class="table-header-group">

回答by Vinay Kumar

in your page, add this CSS

在您的页面中,添加此 CSS

.gvPrinting thead{ write the styles you need.. }

.gvPrinting thead{ 编写您需要的样式.. }

or in the document.ready event ,,

或在 document.ready 事件中,

$('.gvPrinting thead').addClass('table-header-group')

$('.gvPrinting thead').addClass('table-header-group')

Hope this helps :)

希望这可以帮助 :)

回答by Vinay Kumar

What i understood is u need to add the CSSClass for thead element in the serverside code and not by javascript or CSS....

我的理解是你需要在服务器端代码中为 thead 元素添加 CSSClass,而不是通过 javascript 或 CSS ....

for this, use the following code.. it is working for me..

为此,请使用以下代码..它对我有用..

        gridview1.HeaderRow.TableSection = TableRowSection.TableHeader; 
        gridview1.FooterRow.TableSection = TableRowSection.TableFooter;
        gridview1.HeaderStyle.CssClass = "table-header-group";

let me know if this works for you.. sorry for the late reply.

如果这对您有用,请告诉我……抱歉回复晚了。