Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Howto refresh datagrid after update database

Status
Not open for further replies.

AnNguyen

Programmer
Jul 18, 2002
33
0
0
US
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
}

 
Can you describe more clearly what the problem is, I am not following
 
What I usually do it clear the dataset that the datagrid is bound to, and then fill the dataset again. You might need to refresh the grid or something too, but I think it's automatic.

-Freakboy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top