在GridView外观中应用ItemStyle或HeaderStyle [英] Applying ItemStyle or HeaderStyle in GridView Skin

查看:78
本文介绍了在GridView外观中应用ItemStyle或HeaderStyle的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用外观或ASP.NET主题的其他功能(或实际上是任何其他自动方式)将默认的基于列的样式应用于我的 GridView 控件.

I would like to apply default column-based styles to my GridView controls using a skin or other function of ASP.NET themes (or really any other automated way).

当前,我的GridView外观如下:

Currently my GridView skin looks like this:

<asp:GridView runat="server" GridLines="None">
    <HeaderStyle CssClass="GridViewRowHeader" />
    <FooterStyle CssClass="GridViewRowHeader" />
    <RowStyle CssClass="GridViewRowA" />
    <AlternatingRowStyle CssClass="GridViewRowB" />
</asp:GridView>

典型的GridView列定义如下:

And a typical GridView column definition looks like this:

    <Columns>
        <asp:BoundField DataField="ExitTimestamp" HeaderText="Exit" SortExpression="ExitTimestamp">
            <ItemStyle CssClass="GridViewCell" />
            <HeaderStyle CssClass="GridViewHeader" />
        </asp:BoundField>
        <asp:TemplateField HeaderText="Visitor Name/Agency">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("VisitorName") %>'></asp:Label><br />
                <asp:Label ID="Label2" runat="server" Text='<%# Bind("VisitorAgency") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle CssClass="GridViewCell" />
            <HeaderStyle CssClass="GridViewHeader" />
        </asp:TemplateField>
    </Columns>

我想解决的是必须将< ItemStyle> < HeaderStyle> 元素添加到 GridView 控件.我尝试了在外观文件中使用各种方法,包括在其中添加< Columns> 容器和< ItemStyle> 元素,但似乎没有任何效果.有办法吗?

What I would like to get around is having to add the <ItemStyle> and <HeaderStyle> elements to every column definition in my GridView controls. I have tried various ways in the skin file including adding a <Columns> container and <ItemStyle> element therein, but nothing seems to work. Is there a way to do this?

推荐答案

此处的建议可能对您有用 http://forums.asp.net/t/1063057.aspx 并将其添加到您的gridview中,然后使用普通的旧CSS样式表来定位和装饰控件.

The advice here may work for you http://forums.asp.net/t/1063057.aspx in short define and add a CssClass to your gridview then use plain old CSS stylesheet to target and decorate the control.

这篇关于在GridView外观中应用ItemStyle或HeaderStyle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆