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. How to delete a row in a ASP.NET dataGrid

How to delete a row in a ASP.NET dataGrid

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netdesignxml
2 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.
  • I Offline
    I Offline
    Imran Adam
    wrote on last edited by
    #1

    Hello experts i would like to know how to delete a row from a dataGrid (which is in edit mode), i am using paging and the built in edit, update, cancel methods. I have been looking all over the posts most seem to be using databases and since i am using a XML file as my surce of data i am abit lost. heres what i have in my delete event Handler.. private void dgStudents_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int rowToDelete = e.Item.ItemIndex; dsStudents.student.Rows[rowToDelete].Delete(); //refresh datagrid control to show changes BindData(); } the rowToDelete int will get the row to delete, but when i run this and click on delete, i get a runtime error of "There is no Row at position 0" Help please?? Cheers

    Cheers :)

    N 1 Reply Last reply
    0
    • I Imran Adam

      Hello experts i would like to know how to delete a row from a dataGrid (which is in edit mode), i am using paging and the built in edit, update, cancel methods. I have been looking all over the posts most seem to be using databases and since i am using a XML file as my surce of data i am abit lost. heres what i have in my delete event Handler.. private void dgStudents_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int rowToDelete = e.Item.ItemIndex; dsStudents.student.Rows[rowToDelete].Delete(); //refresh datagrid control to show changes BindData(); } the rowToDelete int will get the row to delete, but when i run this and click on delete, i get a runtime error of "There is no Row at position 0" Help please?? Cheers

      Cheers :)

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      hustler2005 wrote:

      dsStudents.student.Rows[rowToDelete].Delete();

      I guess when page is posted back, you will loose this value. Have you checked the count of rows before issuing delete ?

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      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