Problem in Updating records in DataGrid Control

G

Ganapathi Hegde

Hi,

I am new to ASP.NET. I developed an sample application, which displays the
database table on DataGrid Control.
I added Edit, Update, Cancel (Button Column) to Grid Control. Then I
implemented EditCommand, CancelCommand and UpdateCommand

When I click on Edit link text box will display for editing the fild. But I
noticed that, in UpdateCommand still I recieve the old va;ue of text box
even if I changed the values.
But this is happening because AutoPostBack property of text box is false.
This text box is created by framework, is there anyway to overcome this
problem.


Code for your refernce :

private void Grid1_Edit(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) -- EditCommand
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
UpdateData();
}

private void Grid1_Update(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) - UpdateCommand
{

TextBox tb1 = (TextBox) e.Item.Cells[1].Controls[0];
DataRow dr ;
dr = this.ds.Tables[0].Rows[e.Item.ItemIndex];
dr["Test_Case"] = "Test Case2";

try
{
this.adapter.Update(this.ds,"tTestCase");
}
catch(Exception ex)
{
sz = ex.ToString();
}
DataGrid1.EditItemIndex = -1;

UpdateData();

}

private void Grid1_Cancel(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e) - CancelCommand
{
DataGrid1.EditItemIndex = -1;
UpdateData();
}
 
E

Elton Wang

Hi Ganapathi,

I guess that you bind the datagrid's data source every
time, no matter it's in first time or postback. So when
you want to update, before it goes to Update event,
it actually reset textbox value from underlying data
source (of course, it's old value).

HTH

Elton Wang
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top