datagrid update command

Discussion in 'ASP .Net' started by =?Utf-8?B?YWJkb2x5?=, Jun 1, 2004.

  1. 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
     
    =?Utf-8?B?YWJkb2x5?=, Jun 1, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?YWJkb2x5?=

    Scott M. Guest

    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" <> wrote in message
    news:...
    > 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
    >
     
    Scott M., Jun 2, 2004
    #2
    1. Advertising

  3. ----- 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" <> wrote in messag
    news:..
    > 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
     
    =?Utf-8?B?YWJkb2x5?=, Jun 2, 2004
    #3
  4. =?Utf-8?B?YWJkb2x5?=

    Scott M. Guest

    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" <> wrote in message
    news:...
    >
    >
    > ----- 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" <> wrote in message
    > news:...
    > > 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
    >
     
    Scott M., Jun 2, 2004
    #4
  5. "abdoly" <> wrote in message
    news:...
    > hi sir
    > my whole code to update is :
    > public void DataGrid1_UpdateCommand(object

    source,System.Web.UI.WebControls.DataGridCommandEventArgs 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
     
    John Saunders, Jun 2, 2004
    #5
  6. "abdoly" <> wrote in message
    news:...
    >
    > 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="DataGrid1_UpdateCommand"><Column
    s><asp:BoundColumn
    > DataField="deptid" SortExpression="deptid"

    HeaderText="deptid"></asp:BoundColumn><asp:BoundColumn
    >

    DataField="deptname"SortExpression="deptname"HeaderText="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
     
    John Saunders, Jun 4, 2004
    #6
  7. "abdoly" <> wrote in message
    news:...
    > 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,"departments");
    > and the same result , no change in the old value


    I strongly suggest that you simplify your scenario.
    --
    John Saunders
    johnwsaundersiii at hotmail
     
    John Saunders, Jun 4, 2004
    #7
  8. =?Utf-8?B?YWJkb2x5?=

    Scott M. Guest

    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" <> wrote in message
    news:...
    >
    > 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="DataGrid1_UpdateCommand"><Column
    s><asp:BoundColumn
    > DataField="deptid" SortExpression="deptid"

    HeaderText="deptid"></asp:BoundColumn><asp:BoundColumn
    >

    DataField="deptname"SortExpression="deptname"HeaderText="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.
    >
    >
    >
     
    Scott M., Jun 4, 2004
    #8
  9. 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
     
    =?Utf-8?B?YWJkb2x5?=, Jun 4, 2004
    #9
  10. =?Utf-8?B?YWJkb2x5?=

    sobin Guest

    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





    --
    sobin
    ------------------------------------------------------------------------
    Posted via http://www.codecomments.com
    ------------------------------------------------------------------------
     
    sobin, Mar 19, 2005
    #10
  11. =?Utf-8?B?YWJkb2x5?=

    sobin Guest

    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..





    --
    sobin
    ------------------------------------------------------------------------
    Posted via http://www.codecomments.com
    ------------------------------------------------------------------------
     
    sobin, Mar 19, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Blair

    Datagrid update command - and validators

    John Blair, Jan 24, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,236
    vgebrev
    Jan 30, 2008
  2. =?Utf-8?B?c2lhag==?=

    Datagrid update command

    =?Utf-8?B?c2lhag==?=, Feb 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,932
    Craig G
    Feb 28, 2005
  3. =?Utf-8?B?TWljaGFlbA==?=

    How to update datagrid after update

    =?Utf-8?B?TWljaGFlbA==?=, Mar 17, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    502
    Alex D.
    Mar 17, 2006
  4. Andreas Klemt
    Replies:
    0
    Views:
    307
    Andreas Klemt
    Oct 8, 2003
  5. prakash
    Replies:
    2
    Views:
    595
    prakash
    Apr 11, 2005
Loading...

Share This Page