【问题标题】:Remove top border of GridViewRow in c#在c#中删除GridViewRow的上边框
【发布时间】:2018-07-23 16:17:54
【问题描述】:

我在 gridview 的 rowcreated 事件中添加行控件,并且需要删除顶部边框线。

GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
TableCell HeaderCell = new TableCell();
HeaderCell.Text = strTotalRecords;
HeaderCell.HorizontalAlign = HorizontalAlign.Left;
HeaderCell.BorderStyle = BorderStyle.None;
HeaderGridRow.Cells.Add(HeaderCell);
HeaderGridRow.BackColor = Color.White;
gvGrid.Controls[0].Controls.AddAt(totalRowIndex, HeaderGridRow);

我正在使用下面的代码来删除边框,但它不起作用。

HeaderCell.Attributes.CssStyle.Add("border-top", "none");
HeaderCell.Attributes.CssStyle.Add("border-top-style", "none");

HeaderGridRow.Attributes.CssStyle.Add("border-top", "none");    
HeaderGridRow.Attributes.CssStyle.Add("border-top-style", "none");

请建议我如何处理。

【问题讨论】:

  • 你应该在客户端使用 css 而不是服务器端。

标签: c# css asp.net .net gridview


【解决方案1】:

向您的网格添加一个 css 类,并为该 css 类添加样式,如下所示。

.gridview
{
    border-top:none !important;
}

【讨论】:

  • 这些是动态控件,我可能必须在这里处理。这样做怎么样? HeaderGridRow.Attributes.Add("class", "cssclassname");
  • 不管是静态的还是动态的,都不是问题。上面的 css 会将所有具有 gridview 类的元素的边框顶部设置为无
  • 显示生成的html
猜你喜欢
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 2015-01-26
  • 1970-01-01
  • 2012-04-15
相关资源
最近更新 更多