Update Anomaly in DataGrid Control

M

Mo Saghir

I have a problem where I am trying to update a DataGrid command in place
pretty much as outlined in the various samples in MSDN:

private void InitialGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)

{

TextBox txtID = (TextBox)e.Item.Cells[1].Controls[0];

TextBox txtName = (TextBox)e.Item.Cells[2].Controls[0];

Label1.Text = txtID.Text + "-" + txtName.Text + "-";

InitialGrid1.EditItemIndex = -1;

BindData();

}

Whenever I try to access the TextBox.Text field, I get blank if the value
was updated by the user. However, if the value is left untouched then it is
successfully propagated to TextBox.Text field. I've been trying to debug
this for a while now but I am reaching a dead end. The MSDN samples don't
mention any additional details that may pertain to this situation.
Moreover, the data binding is done via:

....

MyConnection.Open();

SqlDataAdapter myCommand = new SqlDataAdapter("select * from UserTable",
MyConnection);



DataSet ds = new DataSet();

myCommand.Fill(ds, "UserTable");

InitialGrid1.DataSource = ds;


InitialGrid1.DataBind();

MyConnection.Close();

Any help would be appreciated as this is currenlty blocking me.
 
S

Scott Mitchell [MVP]

Mo said:
I have a problem where I am trying to update a DataGrid command in place
pretty much as outlined in the various samples in MSDN:
[snip]
Whenever I try to access the TextBox.Text field, I get blank if the value
was updated by the user. However, if the value is left untouched then it is
successfully propagated to TextBox.Text field.

Are you only binding the data to the DataGrid when it is NOT a postback,
or are you binding the data to the DataGrid on ALL page loads?

It sounds like this may be the problem... for more info, see this FAQ:

Why Your DataGrid's Updates Don't Show Up
http://datawebcontrols.com/faqs/Editing/EditedValuesNotSaved.shtml

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top