if (Gridview1.Rows[0].Cells[5].Text.ToString() == textbox1.Text)
{
Loaddata();
}
else
{
lblerror.text = "Error";
textbox2.Focus();
}
See at the earlier point you are checking gridview row index 0. Where there is no row binded to gridview it's before. So how could this "if (Gridview1.Rows[0].Cells[5].Text.ToString() == textbox1.Text)" will work.
YOur condition is wrong that's why it's giving error to you