当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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.

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

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.

网友答案:

As you confirmed the below is working. Great!

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

Now for the header gridview.HeaderRow.Cells[0].CssClass = "something" . Try this out.

Note - only works if AutogenerateColumns = False, won't work for True(default!)

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].

网友答案:

achieved this using CSS as suggested by @dumass

分享给朋友:
您可能感兴趣的文章:
随机阅读: