Internal gridlines in GridView in ASP.NET

烈酒焚心 提交于 2019-12-02 07:09:09

问题


I have a GridView in ASP.NET 2.0 that I want to have show only internal gridlines. Here is my markup and CSS so far:

<asp:GridView ID="myGrid" runat="server" GridLines="None" CssClass="myDataGridClass">
    <Columns>
        ...columns here...
    </Columns>
</asp:GridView>

CSS:

.myDataGridClass>tbody>tr>td /* Apply border to all cells */
{
   border:1px solid black;
}

.myDataGridClass>tbody>tr>th /* Apply border to headers */
{
   border:1px solid black;
}

.myDataGridClass>tbody>tr>td:last-child /* Remove right-side border */
{
   border-right-width:0;
}

.myDataGridClass>tbody>tr>td:first-child /* Remove left-side border */
{
   border-left-width:0;
}

.myDataGridClass>tbody>tr>th:last-child /* Remove right-side header border */
{
   border-right-width:0;
}

.myDataGridClass>tbody>tr>th:first-child /* Remove left-side header border */
{
   border-left-width:0;
}

.myDataGridClass>tbody>tr:last-child>td /* Remove bottom border */
{
    border-bottom-width:0;
}

.myDataGridClass>tbody>tr>th /* Remove top border */
{
   border-top-width:0;
}

Am I right in thinking that there must be an easier way to do this? My method above already does not work in IE, since I'm using last-child.


回答1:


protected void Page_Load(object sender, EventArgs e)
{
    this.myGrid.Attributes.Add("bordercolor", "#000");
}

With the GridView, the declarative bordercolor attribute adds an inline style declaration which only applies to the table itself, not individual cells.

Adding the bordercolor attribute programmatically does not use an inline style, but uses the HTML bordercolor property, which browsers apply to ALL borders inside the table.

See comments under this blog post:

http://codersbarn.com/post/2009/05/31/Set-Color-of-GridLines-in-Gridview.aspx




回答2:


GridLines="None" CellSpacing="2" BackColor="White"


来源:https://stackoverflow.com/questions/6443777/internal-gridlines-in-gridview-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!