473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

datagrid update command

i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being update
that is the code

private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
TextBox temp
temp=(TextBox)e.Item.Cells[0].Controls[0]
String str=temp.Text;

str always returnt the old value of the cell (before being updated)
would u plz tell me about whats wrong i m doin
thnx alo

Nov 18 '05 #1
13 7637
After the update, query the data from the data source by appending a select
SQL statement to the end of your update code or run a stored procedure that
pulls the fresh data down again.
Your code below doesn't show how you are actually updating the data, just
how you are getting the changed data from the input.
"abdoly" <ab****@yahoo.com> wrote in message
news:EA**********************************@microsof t.com...
i wrote a code to update datagrid with the datagrid updatecommand but i cant get the updated values after being updated that is the code

private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e){ TextBox temp;
temp=(TextBox)e.Item.Cells[0].Controls[0];
String str=temp.Text;
}
str always returnt the old value of the cell (before being updated)
would u plz tell me about whats wrong i m doing
thnx alot

Nov 18 '05 #2


----- Scott M. wrote: ----

After the update, query the data from the data source by appending a selec
SQL statement to the end of your update code or run a stored procedure tha
pulls the fresh data down again
Your code below doesn't show how you are actually updating the data, jus
how you are getting the changed data from the input
"abdoly" <ab****@yahoo.com> wrote in messag
news:EA**********************************@microsof t.com..
i wrote a code to update datagrid with the datagrid updatecommand but cant get the updated values after being update that is the cod
private void DataGrid1_UpdateCommand(object source
System.Web.UI.WebControls.DataGridCommandEventArgs e) TextBox temp
temp=(TextBox)e.Item.Cells[0].Controls[0]
String str=temp.Text

str always returnt the old value of the cell (before being updated
would u plz tell me about whats wrong i m doin
thnx alo

thanks for ur care , but my problem is that i need to get the new value wrote in the datagrid text to update the data source with it,whatever how i update the data, i just need to know how to fetch the new value even if i want to preview it on the for
thnk

Nov 18 '05 #3
Here is code that will grab the user inputted data and write it back to the
DataSet that the grid is bound to and rebind the grid. This is what you are
not doing. You must re-bind the grid to the changed dataset in order for
the grid to show the new contents.

Private Sub dg_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles dg.UpdateCommand

' "FindControl" will only accept the name of a control
Dim editObject As Object=
CType(e.Item.Cells(0).FindControl("ControlNameHere "), ControlTypeHere)
ds.Tables(0).Rows(e.Item.ItemIndex).Item("CustID") = edittext.Text

' Repeat the above steps for each column (and control in the grid)

'Get out of edit mode
dg.EditItemIndex = -1

'Update the DataGrid
dg.DataBind()
End Sub
"abdoly" <ab****@yahoo.com> wrote in message
news:87**********************************@microsof t.com...


----- Scott M. wrote: -----

After the update, query the data from the data source by appending a select SQL statement to the end of your update code or run a stored procedure that pulls the fresh data down again.
Your code below doesn't show how you are actually updating the data, just how you are getting the changed data from the input.
"abdoly" <ab****@yahoo.com> wrote in message
news:EA**********************************@microsof t.com...
> i wrote a code to update datagrid with the datagrid updatecommand
but i cant get the updated values after being updated
> that is the code
>> private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e){
> TextBox temp;
> temp=(TextBox)e.Item.Cells[0].Controls[0];
> String str=temp.Text;
> }
> str always returnt the old value of the cell (before being updated)
> would u plz tell me about whats wrong i m doing
> thnx alot
>


thanks for ur care , but my problem is that i need to get the new

value wrote in the datagrid text to update the data source with it,whatever
how i update the data, i just need to know how to fetch the new value even
if i want to preview it on the form thnks

Nov 18 '05 #4
"abdoly" <ab****@yahoo.com> wrote in message
news:CA**********************************@microsof t.com...
hi sir
my whole code to update is :
public void DataGrid1_UpdateCommand(object source,System.Web.UI.WebControls.DataGridCommandEv entArgs e) {
temp=(TextBox)e.Item.Cells[1].Controls[0];
String str=temp.Text;
this.TextBox1.Text=str;
editDr=this.dataSet11.Departments.Rows[e.Item.ItemIndex];
editDr.BeginEdit();
editDr["deptname"]=str;
editDr.EndEdit();
this.Cache["ds"]=this.dataSet11;
this.DataGrid1.EditItemIndex=-1;
this.DataGrid1.DataBind();
}
im using (TextBox) casting because another problem wich is using CType always cause error says that CType is not defined inmy namespace, i tried to
find its base class but i couldnt any way my problem is str always the old value before user update,i think that has nothing to do with updating the dataset because in all cases i will update it with the old value again


I don't see where you updated the database, only the in-memory dataset. Have
you confirmed what the value of "str" is immediately after it is set?

Also, CType didn't work because it's a VB.NET thing. You are correct to use
(TextBox) in C#.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #5


----- John Saunders wrote: -----

"abdoly" <ab****@yahoo.com> wrote in message
news:CA**********************************@microsof t.com...
hi sir
my whole code to update is :
public void DataGrid1_UpdateCommand(object source,System.Web.UI.WebControls.DataGridCommandEv entArgs e) {
temp=(TextBox)e.Item.Cells[1].Controls[0];
String str=temp.Text;
this.TextBox1.Text=str;
editDr=this.dataSet11.Departments.Rows[e.Item.ItemIndex];
editDr.BeginEdit();
editDr["deptname"]=str;
editDr.EndEdit();
this.Cache["ds"]=this.dataSet11;
this.DataGrid1.EditItemIndex=-1;
this.DataGrid1.DataBind();
}
im using (TextBox) casting because another problem wich is using CType always cause error says that CType is not defined inmy namespace, i tried to
find its base class but i couldnt any way my problem is str always the old value before user update,i think that has nothing to do with updating the dataset because in all cases i will update it with the old value again


I don't see where you updated the database, only the in-memory dataset. Have
you confirmed what the value of "str" is immediately after it is set?

Also, CType didn't work because it's a VB.NET thing. You are correct to use
(TextBox) in C#.
--
John Saunders
johnwsaundersiii at hotmail

i m sure that there is misunderstanding here
how can i update the database or the dataset without knowing the value to update with
first i need to know the new value to update my dataset
look,i press the edit link in the datagrid , a textbox contains the value i want to update appears in the cell
then i have to write the new value in the textbox then press update link
in the update event i m supposed to get the value wrote in the datagrid text box and update the dataset with it
my problem is i dont know how to get this value,
another thing, suppose that i dont want to update that value to the database i just want to display it in a label on the web
form, how can i get it to display it
sorry about my week english and ur time
Nov 18 '05 #6
"abdullah" <ab****@yahoo.com> wrote in message
news:DA**********************************@microsof t.com...


----- John Saunders wrote: -----

"abdoly" <ab****@yahoo.com> wrote in message
news:CA**********************************@microsof t.com...
> hi sir
> my whole code to update is :
> public void DataGrid1_UpdateCommand(object source,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
> {
> temp=(TextBox)e.Item.Cells[1].Controls[0];
> String str=temp.Text;
> this.TextBox1.Text=str;
> editDr=this.dataSet11.Departments.Rows[e.Item.ItemIndex];
> editDr.BeginEdit();
> editDr["deptname"]=str;
> editDr.EndEdit();
> this.Cache["ds"]=this.dataSet11;
> this.DataGrid1.EditItemIndex=-1;
> this.DataGrid1.DataBind();
> }
> im using (TextBox) casting because another problem wich is using

CType always cause error says that CType is not defined inmy namespace, i tried to find its base class but i couldnt
> any way my problem is str always the old value before user update,i
think that has nothing to do with updating the dataset
> because in all cases i will update it with the old value again
I don't see where you updated the database, only the in-memory

dataset. Have you confirmed what the value of "str" is immediately after it is set?

Also, CType didn't work because it's a VB.NET thing. You are correct to use (TextBox) in C#.
--
John Saunders
johnwsaundersiii at hotmail

i m sure that there is misunderstanding here
how can i update the database or the dataset without knowing the value to update with first i need to know the new value to update my dataset
look,i press the edit link in the datagrid , a textbox contains the value i want to update appears in the cell then i have to write the new value in the textbox then press update link
in the update event i m supposed to get the value wrote in the datagrid text box and update the dataset with it my problem is i dont know how to get this value,
another thing, suppose that i dont want to update that value to the database i just want to display it in a label on the web form, how can i get it to display it
sorry about my week english and ur time


What I meant is that, given the way you described the problem, it could be
the case that you thought you were updating the database, but no data
changed, or that you had looked at the value of "str" in the debugger and
seen that it hadn't changed. I noticed that the code you provided did not
update the database, so it could have been the first problem. You didn't say
how you had seen the value of "str", so it could have been the second
problem as well.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #7
>> my problem is i dont know how to get this value

(Taken from my earlier post on this thread)

' "FindControl" will only accept the name of a control
Dim editObject As Object=
CType(e.Item.Cells(0).FindControl("ControlNameHere "), ControlTypeHere)
ds.Tables(0).Rows(e.Item.ItemIndex).Item("CustID") = edittext.Text

Note the FindControl method. This is how you "find the control" in the grid
that contains your new data.
Nov 18 '05 #8
"abdoly" <ab****@yahoo.com> wrote in message
news:31**********************************@microsof t.com...

sir
how can i get textbox name to use findControl, the data grid is below

<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP:
104px" runat="server" Width="224px" Height="112px" DataSource="<%# dataSet11 %>"
DataMember="Departments"

AutoGenerateColumns="False"OnUpdateCommand="DataGr id1_UpdateCommand"><Column
s><asp:BoundColumn DataField="deptid" SortExpression="deptid" HeaderText="deptid"></asp:BoundColumn><asp:BoundColumn DataField="deptname"SortExpression="deptname"Heade rText="deptname"></asp:Bou
ndColumn><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn><asp:ButtonColumn Text="Delete"

CommandName="Delete"></asp:ButtonColumn></Columns></asp:DataGrid>

I would not use a BoundColumn. Instead, I'd use a TemplateColumn. That way,
you can name the text box explicitly.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #9
"abdoly" <ab****@yahoo.com> wrote in message
news:E6**********************************@microsof t.com...
sir

according to ur reply i understood that
first: u believe that may be the value already changed but i cant see it for some reasons i made 3 things to if know that right
-i display it on a textbox on the form b4 updating the dataset
this.textBox1.text=str;
but i always see the old value
-i updated the dataset with the str and i wrote the dataset to xml file
after updating it
this.dataSet11.WriteXml(@"d:\x\x.xml");
and i checked the file and the old value was there.
-i used the debugger to watch str and the same result here
second: i have to update the datasource with the dataset every time i need to update a
record, then why i use a dataset if i will go to the server every transaction any way i tried to update the datasource as

this.sqlDataAdapter1.Update(this.dataSet11,"depart ments");
and the same result , no change in the old value


I strongly suggest that you simplify your scenario.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #10
You need to create template columns that you can place your own controls
into. Then you can give the controls the ID's that you want.
"abdoly" <ab****@yahoo.com> wrote in message
news:31**********************************@microsof t.com...

sir
how can i get textbox name to use findControl, the data grid is below

<asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 168px; POSITION: absolute; TOP:
104px" runat="server" Width="224px" Height="112px" DataSource="<%# dataSet11 %>"
DataMember="Departments"

AutoGenerateColumns="False"OnUpdateCommand="DataGr id1_UpdateCommand"><Column
s><asp:BoundColumn DataField="deptid" SortExpression="deptid" HeaderText="deptid"></asp:BoundColumn><asp:BoundColumn DataField="deptname"SortExpression="deptname"Heade rText="deptname"></asp:Bou
ndColumn><asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn><asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn></Columns></asp:DataGrid>
----- Scott M. wrote: -----
>> my problem is i dont know how to get this value

(Taken from my earlier post on this thread)

' "FindControl" will only accept the name of a control
Dim editObject As Object=
CType(e.Item.Cells(0).FindControl("ControlNameHere "),

ControlTypeHere) ds.Tables(0).Rows(e.Item.ItemIndex).Item("CustID") = edittext.Text
Note the FindControl method. This is how you "find the control" in the grid that contains your new data.

Nov 18 '05 #11
si
i used the template columns and i used the findcontrol but the same resul
i will send u the project would u plz just take alook
Nov 18 '05 #12

hi ,
i m also facing with ur problem.. i want to update my database with
new value.. But i'm getting the old value only...

I simply tried to display the new value on to the form, but it is
showing the old value..

Tell me, how to solve this...

Sobin

so****@kgisliim.com

--
sobin
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 19 '05 #13

Hi,,
i m also facing with the same problem..
i tried to update my datagrid with new values using the update
command.. but i m getting the old value only..

i don no how to resolve it..

plz help me..

so****@kgisliim.com

--
sobin
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 19 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: NETDeveloper | last post by:
Hi, I almost have my nested datagrid working properly. I created a datagrid on a user control and dropped that onto another datagrid. At first, I noticed when I was stepping through the code,...
1
by: Gidi | last post by:
helo i have few questions about working with datagrid 1. after i got help from this forum i succeded to move between columns by preesing the enter key, now my questio is how can i decdied which...
0
by: Wayneb | last post by:
Hi I have a datagrid with autogenerates columns based upon a dataset I have constructed from the results of database query - pretty noddy stuff. When you click on Edit I remove the standard...
1
by: AA | last post by:
We want to edit, update data of DataGrid in Asp.Net with VB.Net.and are writing the following code for EditCommand and UpdateCommand Event is : DataGrid1_EditCommand
4
by: Rod | last post by:
I posted a message to this group yesterday asking how to pass parameters to a web form that is the source of an IFrame on a parent web form. I've gotten my answer, and it works. Thanks! Now I...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
1
by: MrMike | last post by:
Hi. My application has dozens of datagrids but for some reason an exception occurs when one of them is updated. When a user edits a datagrid row and then clicks 'Update' the following exception...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: Reney | last post by:
I have a very weird problem in updating my datagrid. Please help me to solve it. The datagrid is tied to a dataset table with five columns. Three of them are primary key and the other two columns...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.