我的GridView有3个绑定列:A,B和C.我想以粗体显示 3列的最高值.如何进行比较并将字体设置为粗体(最好是在aspx文件中)?谢谢.
<Columns>
<asp:BoundField DataField="A" HeaderText="A" SortExpression="A" />
<asp:BoundField DataField="B" HeaderText="B" SortExpression="B" />
<asp:BoundField DataField="C" HeaderText="C" SortExpression="C" />
</Columns>
Run Code Online (Sandbox Code Playgroud)
澄清一下:A,B和C列中的任何NUMERIC值都可以是最大值,具体取决于行.这是我想要设置为粗体的值.
例:
3 **4** 1
**6** 2 0
**9** 1 2
Run Code Online (Sandbox Code Playgroud)
cod*_*der 10
试试这种方式:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int j = 0; j < e.Row.Cells.Count; j++)
{
e.Row.Cells[j].Style.Add("BORDER-BOTTOM", "#aaccee 1px solid");
e.Row.Cells[j].Style.Add("BORDER-RIGHT", "#aaccee 1px solid");
e.Row.Cells[j].Style.Add("padding-left", "5px");
}
}
Run Code Online (Sandbox Code Playgroud)
你需要代码隐藏这种东西.使用RowDataBound用于此目的:
protected void Grid_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int number;
var highestCells = e.Row.Cells.Cast<TableCell>()
.Where(tc => int.TryParse(tc.Text, out number))
.OrderByDescending(c => int.Parse(c.Text));
foreach(var cell in highestCells)
cell.Font.Bold = true;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27511 次 |
| 最近记录: |