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. DataGrid Editing doesn't update

DataGrid Editing doesn't update

Scheduled Pinned Locked Moved Web Development
questionannouncement
4 Posts 3 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.
  • S Offline
    S Offline
    Steve Severance
    wrote on last edited by
    #1

    I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...

    N M 2 Replies Last reply
    0
    • S Steve Severance

      I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Still can't get it? Did you read the article?

      S 1 Reply Last reply
      0
      • N Not Active

        Still can't get it? Did you read the article?

        S Offline
        S Offline
        Steve Severance
        wrote on last edited by
        #3

        I read your article several times. Do I have explicitly have all the items be textboxs? Do I have to process the Textboxs OnTextChanged message even if I just want the end result? If the arguements passed are the original values what use is the update command? Thanks. Steve Not all who wander are lost...

        1 Reply Last reply
        0
        • S Steve Severance

          I am trying to get a datagrid to update. Everything else in it works. However when I try to retrieve the new value it passes me the original value. Any Ideas? Thanks. public void UpdateGrid(object sender, DataGridCommandEventArgs e) { UpdateVendor.Connection = Global.sqlConnection; UpdateVendor.Parameters[0].Value = dgVendors.DataKeys[(int)e.Item.ItemIndex]; UpdateVendor.Parameters[1].Value = ((TextBox)e.Item.Cells[3].Controls[0]).Text; UpdateVendor.Parameters[2].Value = ((TextBox)e.Item.Cells[4].Controls[0]).Text; UpdateVendor.Parameters[3].Value = ((TextBox)e.Item.Cells[5].Controls[0]).Text; UpdateVendor.Parameters[4].Value = ((TextBox)e.Item.Cells[6].Controls[0]).Text; UpdateVendor.ExecuteNonQuery(); dgVendors.EditItemIndex = -1; dgVendors.DataBind(); Response.Redirect("ManageVendors.aspx"); } Steve Not all who wander are lost...

          M Offline
          M Offline
          mgriffith
          wrote on last edited by
          #4

          a couple of points... 1. you are using a global sqlconnection....this could hog resources...i'd at least try to close it after every use and reopen it before every use...the datagrid is good at displaying disconnected data (that's that the System.Data.DataSet object is) 2. make sure you aren't calling DataBind() in your page_load event every time, or else it'll grab the data right from sql again should be something like public void page_load() { if (!Page.IsPostBack) { Page.DataBind(); } else { //do nothing...page was posted back, and data will remain in datagrid unless changed in another function } } hope this helps :eek: michael griffith -------------------- mgriffith@lauren.com mdg12@po.cwru.edu

          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