J
Jon Agiato
Hi, I am trying to use a data grid in a web application in which I have
three tiers. The DataGrid is not set up to a data source, or a data adapter,
so everytime I make a change I send the cell information to another object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can I
take the new data out of the grid after the user makes changes? Thanks very
much!
private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;
// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;
// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;
// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;
// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;
// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);
coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}
Jon Agiato
three tiers. The DataGrid is not set up to a data source, or a data adapter,
so everytime I make a change I send the cell information to another object
which forms an SQL query and makes the query to the DB (actually to a
DBFacade object). In any case, please see the code I have listed below for
my update DataGrid event. With this code, the DB is updated using the old
data in the datagrid prior to the users changes, why is this and how can I
take the new data out of the grid after the user makes changes? Thanks very
much!
private void coursesDataGrid_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// get primary key courseID
TableCell courseIDCell = e.Item.Cells[1];
string courseID = ((TextBox)courseIDCell.Controls[0]).Text;
// get section
TableCell sectionCell = e.Item.Cells[2];
string section = ((TextBox)sectionCell.Controls[0]).Text;
// get semester
TableCell semesterCell = e.Item.Cells[3];
string semester = ((TextBox)semesterCell.Controls[0]).Text;
// get title
TableCell titleCell = e.Item.Cells[4];
string title = ((TextBox)titleCell.Controls[0]).Text;
// get school name
TableCell schoolNameCell = e.Item.Cells[5];
string schoolName = ((TextBox)schoolNameCell.Controls[0]).Text;
// update database here
coursesDataGrid.DataSource = courseManager.UpdateCourse(user, schoolName,
semester, courseID, title, section);
coursesDataGrid.EditItemIndex = -1;
coursesDataGrid.DataBind();
}
Jon Agiato