C# .NET - how to change this code from web application to windows application(asp.net)

Asked By vamsi krishna on 18-Apr-13 08:01 AM
 protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {


        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int val = Convert.ToInt32(e.Row.Cells[3].Text);
            if (val < 20000)
            {
                e.Row.BackColor = System.Drawing.Color.YellowGreen;
            }
            else if (val >= 20000 && val <= 40000)
            {
                e.Row.BackColor = System.Drawing.Color.SkyBlue;
            }
            else
            {
                e.Row.BackColor = System.Drawing.Color.Silver;
            }
        }
    }
Danasegarane Arunachalam replied to vamsi krishna on 18-Apr-13 12:45 PM
Sorry wrong post
Danasegarane Arunachalam replied to vamsi krishna on 18-Apr-13 12:49 PM
In windows form you need to use the Datagridview. And for this particular thing you need to handle the Datagridview.CellFormating Event.


Sample From MSDN: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting.aspx

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
  // If the column is the Artist column, check the
  // value.
  if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Artist")
  {
    if (e.Value != null)
    {
      // Check for the string "pink" in the cell.
      string stringValue = (string)e.Value;
      stringValue = stringValue.ToLower();
      if ((stringValue.IndexOf("pink") > -1))
      {
        e.CellStyle.BackColor = Color.Pink;
      }
 
    }
  }
  else if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
  {
    ShortFormDateFormat(e);
  }
}