简体   繁体   English

将GridView中的所有单元格边框颜色更改为红色

[英]Change all of the cell border colors in a GridView to red

Hi I've tried to change all of the lines vertical and horizontal in my GridView from the code behind using the code shown below, but this does not seem to have any effect. 嗨,我尝试使用下面显示的代码从后面的代码中更改GridView所有垂直和水平线,但这似乎没有任何效果。

Can anyone offer a solution with the code behind please? 任何人都可以提供带有背后代码的解决方案吗?

foreach (GridViewRow row in gvCurrentStageCircsPSTN.Rows)
{
  foreach (TableCell cell in row.Cells)
  {
    cell.Width = 150;
    cell.Height = 20;
    cell.Attributes.CssStyle["text-align"] = "center";
  }
}

Use BorderColor property 使用BorderColor属性

cell.BorderColor = Color.FromName("Red");

In any case, I would recommend you to use css classes to apply styles to get a much more flexible UI layout. 无论如何,我建议您使用css类来应用样式,以获得更加灵活的UI布局。

As you confirmed the below is working. 如您所确认的,下面的方法是有效的。 Great! 大!

border-style:solid; border-width:1px;

Now for the header gridview.HeaderRow.Cells[0].CssClass = "something" . 现在用于标题gridview.HeaderRow.Cells[0].CssClass = "something" Try this out. 试试看

Note - only works if AutogenerateColumns = False, won't work for True(default!) 注意-仅在AutogenerateColumns = False时有效,对True无效(默认值!)

But as Claudio rightly pointed out, all styles should be a part of a css file & you should access them using css classes[preferably only from UI & not from code behind]. 但是正如Claudio正确指出的那样,所有样式都应该是css文件的一部分,并且您应该使用css类访问它们(最好仅从UI而不是后面的代码访问它们)。

使用@dumass建议的CSS实现了此目的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM