namespace DataGridViewOperation{ public partial class Form1 : Form { SqlConnection sqlcon = new SqlConnection(@"Server=RAVI-PC\SQLEXPRESS;database=test1;uid=ravindran;pwd=srirangam;"); SqlCommand sqlcmd = new SqlCommand(); SqlDataAdapter da = new SqlDataAdapter(); DataTable dt = new DataTable(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { LoadGrid(); //Change back color using below method after bind data colorchange(); } void LoadGrid() { sqlcon.Open(); sqlcmd = new SqlCommand("select * from emp", sqlcon); da = new SqlDataAdapter(sqlcmd); da.Fill(dt); bind = true; dataGridView1.DataSource = dt; sqlcon.Close(); } void colorchange() { for(int i =0;i<=99;i++) { dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Aqua; } for(int i =100;i<=199;i++) { dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Blue; } //Make sure split rows based on row count if row is not in that count may be index out of range exception come. }}}