data grid fails to update!

R

rcoco

hi,
I've tried to update my database using my datagrid but there is no
change. here is the code I'm using:

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

{

System.Web.UI.WebControls.TextBox cstaff=new
System.Web.UI.WebControls.TextBox();

cstaff=(System.Web.UI.WebControls.TextBox)e.Item.Cells[1].Controls[0];

SqlCommand myCommand=new SqlCommand("update isp_email.staff set
stafflevel=@stafflevel where id=id",con);



myCommand.Parameters.Add(new
SqlParameter("@stafflevel",SqlDbType.VarChar,45));

myCommand.Parameters["@stafflevel"].Value=cstaff.Text;


con.Open();

myCommand.ExecuteNonQuery();

con.Close();

dgupdate.EditItemIndex=-1;

BindData();

}

ould some one help me?
 
A

Amanda V

OK, I've been searching for an answer to a similar problem. I am using
VB 6.0 though, so I have no idea if the solution I used, will apply/ be
helpful to you at all. I will just throw it out there in case it helps
someone...

I think the DataGrid has a property called 'DataChanged'.

If you set the property to True, then all of the update / validating
stuff should happen.

I had a problem with when I changed values in my datagrid, it didn't
propogate through to the underlying recordset unless I moved to another
record (which in effect, checks the record you were previously on, and
if changes were made, then sets the DataChanged property to true and
does whatever validating is necessary).

Basically I just made a button, that when clicked, sets
DataGrid.DataChanged = True ... and BAM... my underlying recordset was
updated.

Hope it helps someone... :)
 
M

mark carew

Hi,

Is dgupdate your datagrid?
Then you need to execute databind for it and for its datasource

e.g.
dgupdate.sqldatasource1.databind();
dgupdate.databind();

The datagrid has no knowledge that you have updated its underlying data
source. It is just a static snapshot of the data as it previously was
before you changed it.

You have to refresh the datagrid by calling its datasource databind method
and then databind the newly refreshed datasource to the datagrid to re-sync
the data being displayed.

HTH
Mark Carew
 
P

Phil H

Is dgupdate your datagrid?
Then you need to execute databind for it and for its datasource

e.g.
dgupdate.sqldatasource1.databind();
dgupdate.databind();

Sorry Mark but there is no such property as sqldatasource1 in the
DataGrid class and DataBind() is a member of DataGrid not the
DataSource property.

In the code submitted there is a statement:

BindData();

Presumably that is a function defined elsewhere which contains the
necessary commands to bind the ammended data to the grid.

Could the author show it please?
 

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,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top