gpt4 book ai didi

c# - 显示带有背景颜色的百分比条 ASP.Net RowDataBound

转载 作者:行者123 更新时间:2023-11-28 03:12:24 27 4
gpt4 key购买 nike

我有一个 Asp.net Gridview,其中最后一列是我的总数,第 2-x 列是我的数字。

我想显示一个显示百分比的条形图

使用找到的示例 Displaying percentage bar with background color我想修改它以在 RowDataBound 上工作

首先我创建了一个获取样式的方法

 private string colPercent(long Total, long count)
{
var y = decimal.Parse(Total.ToString()) / count;
decimal percent =Math.Round(y,2 );

string _return = $"height:30px; background: -webkit - linear - gradient(left, #efe3af {percent}%,#ffffff {percent}%);";
_return+= $"background: -moz - linear - gradient(left, #efe3af {percent}%, #ffffff {percent}%);";
_return += $"background: -ms - linear - gradient(left, #efe3af {percent}%,#ffffff {percent}%)";
_return += $"background: -o - linear - gradient(left, #efe3af {percent}%,#ffffff {percent}%);";
_return += $" background: linear - gradient(to right, #efe3af {percent}%,#ffffff {percent}%);";

return _return;
}

接下来在 RowDataBind 上循环列

     if (e.Row.RowType == DataControlRowType.DataRow)
{

for (int i = colstart; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Attributes.Add("Style", colPercent(long.Parse(e.Row.Cells [e.Row.Cells.Count -1 ].Text), long.Parse(e.Row.Cells[i].Text)));

}
}

似乎什么都没有改变。有什么问题吗?

最佳答案

答案是先去掉样式中的间距。然后 VS 重新格式化它

   e.Row.Cells[i].Attributes.CssStyle.Value = colPercent(long.Parse(e.Row.Cells[e.Row.Cells.Count - 1].Text), long.Parse(e.Row.Cells[i].Text));

关于c# - 显示带有背景颜色的百分比条 ASP.Net RowDataBound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45642908/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com