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. General Programming
  3. C#
  4. GridView Row Deleting

GridView Row Deleting

Scheduled Pinned Locked Moved C#
tutorialcssdatabasequestion
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.
  • S Offline
    S Offline
    ss mmm
    wrote on last edited by
    #1

    Here am trying to delete the row in the dataset for Delete button click on each row and finally, when I click SAVE button, the entire dataset will be pushed into the db. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { DataSet dsGr = (DataSet)Cache["MyGrid"]; int RowID = (int)GridView1.DataKeys[e.RowIndex].Value; dsGr.Tables[0].Rows[RowID].Delete(); Cache["MyGrid"] = dsGr; GridView1.DataSource = dsGr; GridView1.DataBind(); } The DataKeyNames property for gridview is set to "id". When I delete the first row on the grid, the RowID=1 and hence the first row on the dataset gets deleted but actually the first row (0th row) should be deleted. Can you please suggest if am going wrong on identifying the RowID? int RowID = (int)GridView1.DataKeys[e.RowIndex].Value; Just guide me how to find the correct RowID Thanks.

    J 1 Reply Last reply
    0
    • S ss mmm

      Here am trying to delete the row in the dataset for Delete button click on each row and finally, when I click SAVE button, the entire dataset will be pushed into the db. protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { DataSet dsGr = (DataSet)Cache["MyGrid"]; int RowID = (int)GridView1.DataKeys[e.RowIndex].Value; dsGr.Tables[0].Rows[RowID].Delete(); Cache["MyGrid"] = dsGr; GridView1.DataSource = dsGr; GridView1.DataBind(); } The DataKeyNames property for gridview is set to "id". When I delete the first row on the grid, the RowID=1 and hence the first row on the dataset gets deleted but actually the first row (0th row) should be deleted. Can you please suggest if am going wrong on identifying the RowID? int RowID = (int)GridView1.DataKeys[e.RowIndex].Value; Just guide me how to find the correct RowID Thanks.

      J Offline
      J Offline
      Jpuckett
      wrote on last edited by
      #2

      Should be: int RowID = e.RowIndex; This gets the correct Index for the row that fired the event.

      S 1 Reply Last reply
      0
      • J Jpuckett

        Should be: int RowID = e.RowIndex; This gets the correct Index for the row that fired the event.

        S Offline
        S Offline
        ss mmm
        wrote on last edited by
        #3

        :laugh: Thanks. I was finding the value.

        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