0
我有一個Asp.net GridView,其中最後一列是我的總和col 2-x將是我的號碼。顯示百分比欄與背景顏色ASP.Net RowDataBound
我想顯示一個欄顯示的百分比
使用發現Displaying percentage bar with background color 我想修改它的工作onRowDataBound
首先我創建了一個方法來獲得風格
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)));
}
}
沒有什麼似乎在改變。有什麼可能是錯的?