网格线不显示在ASP.NET GridView中

eqqqjvef  于 2023-01-18  发布在  .NET
关注(0)|答案(1)|浏览(238)

我有一个奇怪的问题与ASP.NET GridView控件。它不会显示垂直线,无论我做什么。我已经设置如下:

<asp:GridView runat="server" ID="gvActivity" AllowPaging="true" PageSize="10" AutoGenerateColumns="false" GridLines="Both" BorderColor="#000000" BorderStyle="Solid"
    EmptyDataText="No Data Found"  Width="100%">
    <EmptyDataRowStyle ForeColor="#990000" HorizontalAlign="Center" Font-Bold="true" Font-Size="X-Large" />
    <RowStyle BackColor="#ffffff" ForeColor="#000000" BorderColor="#000000" font-names="corbel, verdana, arial" Font-Size="14px" />
    <AlternatingRowStyle BackColor="#ffffcc" ForeColor="#000000" BorderColor="#000000" font-names="corbel, verdana, arial" Font-Size="14px" />
    <HeaderStyle BackColor="#006699" ForeColor="#ffffff" HorizontalAlign="Center" BorderColor="#000000" font-names="corbel, verdana, arial" Font-Size="14px" />
    <Columns>
        <asp:BoundField DataField="ActivityDate" HeaderText="Date" DataFormatString="{0:d}" ItemStyle-Width="20%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="NewCustomers" HeaderText="Customers" DataFormatString="{0:n0}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="BidPackSales" HeaderText="Packs" DataFormatString="{0:n0}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="BidPackTotal" HeaderText="Pack Ttl" DataFormatString="{0:c}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="BPCommissions" HeaderText="Pack Comm." DataFormatString="{0:c}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="BoxSales" HeaderText="Boxes" DataFormatString="{0:n0}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="MBCommissions" HeaderText="Box Comm." DataFormatString="{0:c}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="TotalCommissions" HeaderText="Total Comm." DataFormatString="{0:c}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField DataField="PaidOn" HeaderText="Paid" DataFormatString="{0:d}" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Right" />
    </Columns>
</asp:GridView>

行之间的水平线显示出来了,但分隔单元格的垂直线没有。这方面有什么帮助吗?

doinxwow

doinxwow1#

嗯,我看到了线条。所以,要么你在那一页上有一些零散的css。
我也会考虑清除你的浏览器缓存。还有,试着改变缩放比例。
我没有你的数据,但如果你的gv,并在我自己的列,这样说:

<asp:GridView runat="server" ID="gvActivity" AllowPaging="true" 
    PageSize="10" AutoGenerateColumns="false" GridLines="Both" BorderColor="#000000" 
    BorderStyle="Solid"
    EmptyDataText="No Data Found" Width="100%">
    <EmptyDataRowStyle ForeColor="#990000" HorizontalAlign="Center" Font-Bold="true" Font-Size="X-Large" />
    <RowStyle BackColor="#ffffff" ForeColor="#000000" BorderColor="#000000" Font-Names="corbel, verdana, arial" Font-Size="14px" />
    <AlternatingRowStyle BackColor="#ffffcc" ForeColor="#000000" BorderColor="#000000" Font-Names="corbel, verdana, arial" Font-Size="14px" />
    <HeaderStyle BackColor="#006699" ForeColor="#ffffff" HorizontalAlign="Center" BorderColor="#000000" Font-Names="corbel, verdana, arial" Font-Size="14px" />
    <Columns>
        <asp:BoundField DataField="Fighter" HeaderText="Fighter" />
        <asp:BoundField DataField="Engine" HeaderText="Engine" />
        <asp:BoundField DataField="Thrust" HeaderText="Thrust" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:TemplateField HeaderText="Preview">
            <ItemTemplate>
                <asp:Image ID="Image2" runat="server" Width="150px"
                    ImageUrl='<%# Eval("ImagePath")%>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

然后要加载的代码如下:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
        LoadGrid();

}

void LoadGrid()
{
    using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.TEST4))
    {
        string strSQL = "SELECT * FROM Fighters";
        using (SqlCommand cmdSQL = new SqlCommand(strSQL,conn))
        {
            conn.Open();
            DataTable rstData = new DataTable();
            rstData.Load(cmdSQL.ExecuteReader());
            gvActivity.DataSource = rstData;
            gvActivity.DataBind();
        }
    }
}

我明白了:

并且考虑使用bootstrap类。你的项目中可能包含bootstrap类,它们往往会毫不费力地让你的gv看起来非常漂亮。
让我们扔掉你所有的颜色,试试这个:

<asp:GridView runat="server" ID="gvActivity" AllowPaging="true" 
    PageSize="10" AutoGenerateColumns="false" 
    EmptyDataText="No Data Found" Width="100%"
    CssClass="table table-hover table-striped">
    <Columns>
        <asp:BoundField DataField="Fighter" HeaderText="Fighter" />
        <asp:BoundField DataField="Engine" HeaderText="Engine" />
        <asp:BoundField DataField="Thrust" HeaderText="Thrust" />
        <asp:BoundField DataField="Description" HeaderText="Description" />
        <asp:TemplateField HeaderText="Preview">
            <ItemTemplate>
                <asp:Image ID="Image2" runat="server" Width="150px"
                    ImageUrl='<%# Eval("ImagePath")%>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

我们现在得到这个:

所以,我们看到/得到了交替的行阴影,文本和间距实际上是相当不错的。(填充周围的方块是更好的)。而且不需要一堆混乱的手工建立的格式。
但是,尝试不同的浏览器,尝试改变缩放,尝试清除浏览器缓存。
如果需要,可以尝试给予引导类
这些:

CssClass="table table-hover table-striped"

例如:

相关问题