Not getting new values with UpdateCommand in Datagrid

M

Marc Eggenberger

Hi there.

I have a datagrid on a webpage where I added a Edit Column with
"Property Builder - Columns - Button Column - Edit, Update, Cancel
Column.

Then when loading the page I do the following:

private void Page_Load(object sender, System.EventArgs e)
{
//Set Version
this.lblInfo.Text = "UniqueID Creation Tool V" +
System.Configuration.ConfigurationSettings.AppSettings["Version"];

//Obtain Menu and databind to list control
UniqueUserInterface.Proxy.UniqueID wsUnique = new
UniqueID();
this.dgCharReplacement.DataSource =
wsUnique.GetCharReplacements();
this.dgCharReplacement.DataKeyField =
"OriginalChar";
this.dgCharReplacement.DataBind();

}


I get a DataSet from a WebService and Bind the DataSet to the Grid on
runtime. This works well.

I also have

private void dgCharReplacement_EditCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.dgCharReplacement.EditItemIndex =
e.Item.ItemIndex;
this.dgCharReplacement.DataBind();
}

Which handles the EditCommand of the DataGrid.

This also works, it changes, displays a Update, Cancel und I can edit
the values (only two text columns)

The CancelCommand I handle with

private void dgCharReplacement_CancelCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.dgCharReplacement.EditItemIndex = -1;
this.dgCharReplacement.DataBind();
}

which also works ... But with the update I have problems.

I try to handle it with:

private void dgCharReplacement_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
log.Debug("Entering
dgCharReplacement_UpdateCommand");
UniqueUserInterface.Proxy.UniqueID wsUnique = new
UniqueID();
try
{
string strOriginalChar = ((TextBox)
e.Item.Cells[1].Controls[0]).Text;
string strNewChar = ((TextBox)e.Item.Cells
[2].Controls[0]).Text;
int return_value =
wsUnique.UpdateCharReplacement(strOriginalChar, strNewChar);
if(return_value != 0)
{
//TODO: Errorhandling
log.Error("Error while Updateing the
Char " + strOriginalChar + " with " + strNewChar );
}
}
catch(Exception fehler)
{
//TODO: Errorhandling
log.Error("Error while Updateing the Char " +
((TextBox)e.Item.Cells[1].Controls[0]).Text + " with " + ((TextBox)
e.Item.Cells[2].Controls[0]).Text + ". Error: " + fehler.Message);
}

//Obtain Menu and databind to list control
this.dgCharReplacement.DataSource =
wsUnique.GetCharReplacements();
this.dgCharReplacement.DataKeyField =
"OriginalChar";
this.dgCharReplacement.DataBind();
}

But strNewChar always has the value of the old textbox ... I never get
the new value. Why? I only bind later so shouldnt it have the new value?
 
M

Marc Eggenberger

Hi there.

I have a datagrid on a webpage where I added a Edit Column with
"Property Builder - Columns - Button Column - Edit, Update, Cancel
Column.

Then when loading the page I do the following:

private void Page_Load(object sender, System.EventArgs e)
{
//Set Version
this.lblInfo.Text = "UniqueID Creation Tool V" +
System.Configuration.ConfigurationSettings.AppSettings["Version"];

//Obtain Menu and databind to list control
UniqueUserInterface.Proxy.UniqueID wsUnique = new
UniqueID();
this.dgCharReplacement.DataSource =
wsUnique.GetCharReplacements();
this.dgCharReplacement.DataKeyField =
"OriginalChar";
this.dgCharReplacement.DataBind();

}

Darn .... I often forget ....

I had to put a

if(!Page.IsPostBack)
{
....
}

around it ... sorry mates ...
 

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,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top