I have a gridview that is created dynamically in the back end of the code. The gridview is populated depending on the data entered into the form. When the submit button is selected the gridview is populated with the results, however when the user fills the form in the second time and selects the submit button the results in the gridview do not change. I'm not sure how I can rebind the gridview as it is dynamically created and placed in a <div> on the front end.
Below is the code I use to create the gridview
GridView gridview1 = new GridView();
gridview1.AutoGenerateColumns = false;
for (int i = 0; i < datasource.Columns.Count; i++)
{
BoundField boundfield = new BoundField();
boundfield.DataField = datasource.Columns[i].ColumnName.ToString();
boundfield.HeaderText = datasource.Columns[i].ColumnName.ToString();
gridview1.Columns.Add(boundfield);
}
gridview1.DataSource = datasource;
gridview1.DataBind();
gridview.Controls.Add(gridview1);
Any help would be great.