Hello everyone
how can i refresh datagrid after updating database.
First of all i'll describe my problem.
I have a webform with a datagrid and a save button. The datagrid consist of row of fields: ID, Name Price, Price is a editable textbox. User can edit as many of the price Textbox as needed, click save button to update all changes back to the database, and the grid will be rebind. The problem is that after rebind , I get thegrid with 6 field as ID,Name, Price, ID,Name ,Price.
Do i miss something here or how can i clear the content of the Grid before rebind?
Any help would be much appreciated. ( please refer to my code below)
Thanks.
private void Page_Load(object sender, System.EventArgs e)
{
btnUpdate.Attributes.Add("OnClick", "return confirm('Are you sure you want to save?');");
myDB = new Dbase();
sqlConn = myDB._Connect(sDB);
sqlConn.Open();
BuildDataGrid();
}
private void BuildDataGrid();
{
// connect to database, fetch data to a dataset DS , bind it to DtaGrrid
DG.DataSource = DS.Tables[0];
DG.DataBind();
}
private void btnUpdate_Click(object sender,System.EventArgs e)
{
// Update database here ....fully tested
BuildDataGrid(); // rebind the data grid after updating
}
how can i refresh datagrid after updating database.
First of all i'll describe my problem.
I have a webform with a datagrid and a save button. The datagrid consist of row of fields: ID, Name Price, Price is a editable textbox. User can edit as many of the price Textbox as needed, click save button to update all changes back to the database, and the grid will be rebind. The problem is that after rebind , I get thegrid with 6 field as ID,Name, Price, ID,Name ,Price.
Do i miss something here or how can i clear the content of the Grid before rebind?
Any help would be much appreciated. ( please refer to my code below)
Thanks.
private void Page_Load(object sender, System.EventArgs e)
{
btnUpdate.Attributes.Add("OnClick", "return confirm('Are you sure you want to save?');");
myDB = new Dbase();
sqlConn = myDB._Connect(sDB);
sqlConn.Open();
BuildDataGrid();
}
private void BuildDataGrid();
{
// connect to database, fetch data to a dataset DS , bind it to DtaGrrid
DG.DataSource = DS.Tables[0];
DG.DataBind();
}
private void btnUpdate_Click(object sender,System.EventArgs e)
{
// Update database here ....fully tested
BuildDataGrid(); // rebind the data grid after updating
}