Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. DataGrid Update doesn't update

DataGrid Update doesn't update

Scheduled Pinned Locked Moved ASP.NET
cssdatabasehelpannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nit115
    wrote on last edited by
    #1

    Hey all, any help would be appreciated. I have written a webform that has a datagrid. I am trying to get it to update but it will not update the changes. My code is listed below please help. I have no errors: Whats happens is the eventArgs does not pick up the changes but only the old values. Thanks public void UpdateCommand(Object sender, DataGridCommandEventArgs e) { //Retrieve items from Grid. string custID = ((TextBox)(e.Item.Cells[0].Controls[0])).Text; string cgARName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text; string arPrice = ((TextBox)(e.Item.Cells[2].Controls[0])).Text; string arDesc = ((TextBox)(e.Item.Cells[3].Controls[0])).Text; arPrice = arPrice.Substring(1, arPrice.Length -1); double cost = double.Parse( arPrice ); //SQL Update Information SqlConnection sqlCon = new SqlConnection("myconnection"); string update = "UPDATE ActionRequestitems SET actionName = '" + cgARName + "',actioncost =" + cost + ",description = '" + arDesc + "' WHERE actionid = '" + "1" + "'"; sqlCon.Open(); SqlCommand myCommand = new SqlCommand(update); myCommand.Connection = sqlCon; myCommand.ExecuteNonQuery(); myCommand.Connection.Close(); sqlCon.Close(); // Reset the edit mode for the current item MyGrid.EditItemIndex = -1; // Refresh the grid BuildDataGrid(); }

    V 1 Reply Last reply
    0
    • N nit115

      Hey all, any help would be appreciated. I have written a webform that has a datagrid. I am trying to get it to update but it will not update the changes. My code is listed below please help. I have no errors: Whats happens is the eventArgs does not pick up the changes but only the old values. Thanks public void UpdateCommand(Object sender, DataGridCommandEventArgs e) { //Retrieve items from Grid. string custID = ((TextBox)(e.Item.Cells[0].Controls[0])).Text; string cgARName = ((TextBox)(e.Item.Cells[1].Controls[0])).Text; string arPrice = ((TextBox)(e.Item.Cells[2].Controls[0])).Text; string arDesc = ((TextBox)(e.Item.Cells[3].Controls[0])).Text; arPrice = arPrice.Substring(1, arPrice.Length -1); double cost = double.Parse( arPrice ); //SQL Update Information SqlConnection sqlCon = new SqlConnection("myconnection"); string update = "UPDATE ActionRequestitems SET actionName = '" + cgARName + "',actioncost =" + cost + ",description = '" + arDesc + "' WHERE actionid = '" + "1" + "'"; sqlCon.Open(); SqlCommand myCommand = new SqlCommand(update); myCommand.Connection = sqlCon; myCommand.ExecuteNonQuery(); myCommand.Connection.Close(); sqlCon.Close(); // Reset the edit mode for the current item MyGrid.EditItemIndex = -1; // Refresh the grid BuildDataGrid(); }

      V Offline
      V Offline
      VenkatFor NET
      wrote on last edited by
      #2

      what do you have in BuildDataGrid method Bhaskara

      N 1 Reply Last reply
      0
      • V VenkatFor NET

        what do you have in BuildDataGrid method Bhaskara

        N Offline
        N Offline
        nit115
        wrote on last edited by
        #3

        Thanks for the help. It was I didn't put in the page_load, to not rebuild the datagrid. if( !IsPostback ) { builddatagrid(); } thanks for the help.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups