2017-08-11 3 views
0

私は、最後の列が私の合計で、col 2-xが自分の番号になるAsp.net Gridviewを持っています。私は例を使用してパーセントにバックグラウンドカラーでパーセンテージバーを表示ASP.Net RowDataBound

を示すバーを表示したい

Displaying percentage bar with background color を見つけた私は、スタイル

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; 
    } 
を取得するためのメソッドを作成

ファーストをonRowDataBound動作するようにそれを変更したいです

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))); 

     } 
    } 

何も変わっていないようです。何が間違っているのでしょうか?

答えて

0

答えはまずスタイル内のスペースを削除することです。 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)); 
関連する問題