I've utilized the sample "Save and Retrieve Dynamic TextBox values in GridView to SQL Server Database in ASP.Net Web Application" but I'm having some trouble altering it. Instead of saving directly to a SQL table I need to pass the contents of the dynamic gridview to a label, which will update the DB using a stored Procedure. I get the error: Unable to cast object of type 'System.Web.UI.WebControls.GridViewRow' to type 'System.Data.DataRow'. Here is the code I'm using, I've added an additional button control & label. Any ideas? I feel like I'm close to a solution, but DataRow is a problem.
protected void btnPrintValues_Click(object sender, EventArgs e)
{
lblVehicles.Text = "";
foreach (DataRow row in Gridview1.Rows)
{
for (int i = 0; i < Gridview1.Rows.Count - 1; i++)
{
lblVehicles.Text += String.Format("TextBox {0} Value:<b>{1}</b> ,", i + 1,
((TextBox)Gridview1.Rows[i].Controls[0]).Text);
}
lblVehicles.Text += "<br/>";
}
}