I'm trying to save a GridView
to a DataTable
.
I have code which should in theory do it but I keep getting this error:
Column 0 doesn't exist
Here is my code:
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
for (int j = 0; j < GridView1.Rows.Count; j++)
{
DataRow dr;
GridViewRow row = GridView1.Rows[j];
dr = dt.NewRow();
for (int i = 0; i < row.Cells.Count; i++)
{
dr[i] = row.Cells[i].Text;
}
dt.Rows.Add(dr);
}
}
Any help on how to fix this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…