2016-03-22 13 views
-3

gridviewの2つの列があり、1つは値を持ち、もう1つは毎月得ます。条件演算子(>または<)を使用して2つの列を比較したいと思います。 次のコードを使用しましたが、動作しません。条件付き演算子をCでのgridview列の使用方法

protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     string Threshold = e.Row.Cells[3].Text; 
     int result = int.Parse(Threshold.Replace("%", "")); 

     int ThreCol; 
     int ResCol; 

     ThreCol = int.Parse(e.Row.Cells[3].Text); 
     ResCol = int.Parse(e.Row.Cells[4].Text); 

      if (e.Row.Cells[4].Text == result.ToString().Trim()) 
      { 
       e.Row.Cells[4].BackColor = Color.MediumSeaGreen; 
      } 
       if (ResCol > ThreCol) 
      { 
       e.Row.Cells[4].BackColor = Color.Yellow; 
      } 
      else 
      { 
       e.Row.Cells[4].BackColor = Color.LightCoral; 
      } 
     } 
    } 

エラー

入力文字列が正しい形式ではありませんでした。 (ロブコメントで述べたように)あなたはParseintない文字列をしようとしているので、

screenshot of the error

+5

エラーが発生している行を見てください。次に、エラーメッセージを再度読んでください: '入力文字列が正しい形式ではありませんでした。文字列を整数に解析しようとしていますが、文字列が無効です。 – Rob

+6

解決方法は、デバッガを使用して、どの行が壊れているかを調べ、文字列を見て、文字列が数字でない理由、またはそれが数字だと思っている理由を理解することです。 SOはデバッグサービスではありません。 – Rob

+0

グリッドビューを表示してください – fubo

答えて