我在我的項目中有一個gridview控件,我想將多個gridview行保存回數據庫。我如何通過循環保存所有行。請幫我解決這個問題。如何將多個gridview行數據保存到asp.net中的數據庫c#
//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();
}
}
請顯示gridview標記 – naveen 2015-02-11 09:05:59