c# - 为什么我的 GridView CSSClass 没有被应用?

标签 c# css asp.net gridview

我正在尝试在 ASP.net 中建立一个新网页。我正在使用带有分页的 gridview,但是我尝试使用的 CSS 类没有得到应用。页面其余部分的 CSS 正在运行,它只是与这个 gridview 有关。我无法通过谷歌找到答案。请帮忙,我们将不胜感激!

我曾尝试将 CSS 类更改为类,我已尝试更改 CSS 类,我已尝试从 Site Master 中删除 CSS 链接,我已尝试从 Gridview 周围删除 DIV 容器,但这些都没有成功区别。

GridView :

<%--Records of the graphed data --%>
    <div class="Records">
<h4>Shutdown Records</h4>
        <asp:GridView ID="datagrid" runat="server" DataSourceID="SqlDataSource6" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" 
           PageSize="6" AllowPaging="True" OnPageIndexChanging="datagrid_PageIndexChanging" Width="100%">
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource6" runat="server" 
        ConnectionString="<%$ ConnectionStrings:Automation %>"
        ProviderName="System.Data.SqlClient" SelectCommand="select ShutdownDate, ShutdownNotes, StartupDate, StartupNotes, Cast
(
    Round 
    (
        (
        Cast
            (
            SUM(TotalDownTime)as decimal(18, 2)
            )/3600
        )
    , 2 
    ) as decimal(18, 2) 
) as 'Duration of Shutdowns (Hours)' 
from ProductionShutdownRecord 
where Reason like '%'+@Reason+'%'
and ShutdownNotes like '%'+@shutdownNotes+'%'
and StartupNotes like '%'+@startupNotes+'%'
and ShutdownDate &gt;= @startDate
and ShutdownDate &lt;= @endDate
and AMSTaskRelated like 
    CASE 
        when @AMS = 1 then '%1%'
        else '%%'
    END
group by ShutdownDate, ShutdownNotes, StartupDate, StartupNotes
order by shutdowndate asc
">
                <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" DefaultValue="Scheduled Release" 
                    Name="Reason" PropertyName="SelectedValue" Type="String" />
                <asp:ControlParameter ControlID="shutdownNotes" ConvertEmptyStringToNull="False" 
                    Name="shutdownNotes" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="startupNotes" ConvertEmptyStringToNull="False" 
                    Name="startupNotes" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="startDate" ConvertEmptyStringToNull="False" 
                    Name="startDate" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="endDate" ConvertEmptyStringToNull="False" 
                    Name="endDate" PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="AMSCheck"
                    Name="AMS" PropertyName="Checked"/>
                </SelectParameters>
</asp:SqlDataSource>
</div>

CSS:

/* Gridview Style
-------------------------------------------------------------------------------------------------------------*/
.mGrid {
    width: 100%;
    background-color: #fff;
    margin: 5px 0 10px 0;
    border: solid 1px #525252;
    border-collapse: collapse;
}

    .mGrid td {
        padding: 2px;
        border: solid 1px #c1c1c1;
        color: #717171;
    }

    .mGrid th {
        padding: 4px 2px;
        color: #fff;
        background: #424242 url(grd_head.png) repeat-x top;
        border-left: solid 1px #525252;
        font-size: 0.9em;
    }

    .mGrid .alt {
        background: #fcfcfc url(grd_alt.png) repeat-x top;
    }

    .mGrid .pgr {
        background: #424242 url(grd_pgr.png) repeat-x top;
    }

        .mGrid .pgr table {
            margin: 5px 0;
        }

        .mGrid .pgr td {
            border-width: 0;
            padding: 0 6px;
            border-left: solid 1px #666;
            font-weight: bold;
            color: #fff;
            line-height: 12px;
        }

        .mGrid .pgr a {
            color: #666;
            text-decoration: none;
        }

            .mGrid .pgr a:hover {
                color: #000;
                text-decoration: none;
            }

预期结果:我正在尝试使用此 CSS 模板: http://atashbahar.com/post/2009-01-23-aspnet-gridview-makeover-using-css

实际结果: 我得到一个纯白色的 GridView 。

最佳答案

为了后人的缘故,问题可以有答案,我会在这里写出解决方案。

使用键盘快捷键 Ctrl + Shift + R 来清除浏览器的缓存。现代浏览器缓存 javascript 和 css 文件等资源,以便您下次访问时,它们的加载速度更快。如果您更改了 CSS 而它们没有出现,则很可能您的浏览器仍在使用缓存版本。

如果您担心您的用户看到的是缓存资源而不是更新的资源,请查看这些 cache busting techniques以帮助防止这些问题。

关于c# - 为什么我的 GridView CSSClass 没有被应用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58135802/

相关文章:

c# - 从 MVC 中的 List<object> 填充 Razor 下拉列表

c# - 如何将 blob 数据转换为字符串?

javascript - 如何显示图片

c# - Viewstate 上的 TextBox 值?

jquery - 打开日历时保持 div 打开

c# - 如何按指定值返回 MySQL 表条目 ASP.net/C#

c# - 使用c#以json格式保存数据

javascript - 根据 URL 激活特定选项卡

javascript - 将div定位在input的右下角

css - 减少标题之间的间距