I have a gridview control in my project in which i wanted to save multiple gridview rows back to the database. How do i get save all rows through looping. Please help me to overcome this problem.

//Save TestDetails
foreach (GridViewRow rw in GridView1.Rows)
{
var n = new TestDetail
{
ServiceId = Convert.ToInt32(GridView1.DataKeys[rw.RowIndex].Value),
Service = rw.Cells[1].Text.ToString(), //getting input error
Price = Convert.ToInt32(rw.Cells[2].Text.ToString()) //getting input error
};
using (var context = new DiagEntities())
{
context.TestDetail.Add(n);
context.SaveChanges();
}
}