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. Trouble getting value out of a GridView cell being edited

Trouble getting value out of a GridView cell being edited

Scheduled Pinned Locked Moved ASP.NET
questioncsssql-serversysadminhelp
2 Posts 1 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.
  • I Offline
    I Offline
    InvalidTypecast
    wrote on last edited by
    #1

    I have a GridView on my page that I am updating in the aspx.cs file instead of the aspx page. I have been able to get the SELECTs and DELETEs working OK, but the UPDATE command is giving me problems. I tracked it down to the fact that my code is not picking up the value of the cell I edit and then Update. For example, I have a GridView, populated from mssql, with the following columns Product Name | Ordered | Unit Price | Total All of the columns except for Ordered are set to read only. I have the template columns Edit and Delete. When I click Edit my template columns switch to Update and Cancel and the Ordered column's cell for the coressponding row turns into a textBox that I can type a new value in. When I click Update my page posts, but the value I typed in is not used. I think I am trying to access the value wrong. I am using Server.HtmlDecode to get the value out of the cell, but my suspicion is that it doesn't work for cells being edited. If that is the problem, what is the correct method? protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = GridView1.Rows[(Convert.ToInt32(e.CommandArgument))]; string productName = Server.HtmlDecode(row.Cells[0].Text); /*Various if/else if statements to catch the grid commands left out of here for brevity*/ else if (e.CommandName == "Update") { if (Session["orderIDandDate"] != null) { //the quantity value below isn't picking up the value in this row //the problem is most likely here--maybe using the wrong method quantity = Convert.ToInt32(Server.HtmlDecode(row.Cells[1].Text)); if (Convert.ToInt32(quantity) > 0) { SqlDataSource2.UpdateCommand = String.Format("UPDATE TABLE SET quantity = '{0}' WHERE (product = '{1}') AND (order = '{2}')", quantity, productName, orderID); SqlDataSource2.Update(); } } }

    I 1 Reply Last reply
    0
    • I InvalidTypecast

      I have a GridView on my page that I am updating in the aspx.cs file instead of the aspx page. I have been able to get the SELECTs and DELETEs working OK, but the UPDATE command is giving me problems. I tracked it down to the fact that my code is not picking up the value of the cell I edit and then Update. For example, I have a GridView, populated from mssql, with the following columns Product Name | Ordered | Unit Price | Total All of the columns except for Ordered are set to read only. I have the template columns Edit and Delete. When I click Edit my template columns switch to Update and Cancel and the Ordered column's cell for the coressponding row turns into a textBox that I can type a new value in. When I click Update my page posts, but the value I typed in is not used. I think I am trying to access the value wrong. I am using Server.HtmlDecode to get the value out of the cell, but my suspicion is that it doesn't work for cells being edited. If that is the problem, what is the correct method? protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = GridView1.Rows[(Convert.ToInt32(e.CommandArgument))]; string productName = Server.HtmlDecode(row.Cells[0].Text); /*Various if/else if statements to catch the grid commands left out of here for brevity*/ else if (e.CommandName == "Update") { if (Session["orderIDandDate"] != null) { //the quantity value below isn't picking up the value in this row //the problem is most likely here--maybe using the wrong method quantity = Convert.ToInt32(Server.HtmlDecode(row.Cells[1].Text)); if (Convert.ToInt32(quantity) > 0) { SqlDataSource2.UpdateCommand = String.Format("UPDATE TABLE SET quantity = '{0}' WHERE (product = '{1}') AND (order = '{2}')", quantity, productName, orderID); SqlDataSource2.Update(); } } }

      I Offline
      I Offline
      InvalidTypecast
      wrote on last edited by
      #2

      Ok, on about my 5th google search result page I found it :) If you do this from the GridView_RowUpdating function you can use e.NewValues to get the new value. Problem solved :)

      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