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. GridView issue........Anyone...........please?

GridView issue........Anyone...........please?

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharpasp-netdesign
4 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
    sanju0276
    wrote on last edited by
    #1

    Here is the code from ASP.NET 1.1 that works. My problem is below with 2.0 GridView? private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int playerID = Convert.ToInt32(e.Item.Cells[1].Text); string sqlDelete = "delete Players where PlayerID = '" + playerID +"'"; SqlConnection conn = new SqlConnection(dsn); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sqlDelete; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; BindGrid(); } This above code is ASP.NET 1.1 code for Deletion from DataGrid. It works fine. Now, I am using GridView (ASP.NET 2.0) The problem I am having is getting the playerID from GridView? ***int playerID = Convert.ToInt32(e.Item.Cells[1].Text); ** does not give any playerID but throws error? How do I get the playerID from GridView. Is the event handler Row Deleting or Row Deleted? Please help............. Sanjeev

    C 1 Reply Last reply
    0
    • S sanju0276

      Here is the code from ASP.NET 1.1 that works. My problem is below with 2.0 GridView? private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { int playerID = Convert.ToInt32(e.Item.Cells[1].Text); string sqlDelete = "delete Players where PlayerID = '" + playerID +"'"; SqlConnection conn = new SqlConnection(dsn); SqlCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = sqlDelete; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); DataGrid1.EditItemIndex = -1; BindGrid(); } This above code is ASP.NET 1.1 code for Deletion from DataGrid. It works fine. Now, I am using GridView (ASP.NET 2.0) The problem I am having is getting the playerID from GridView? ***int playerID = Convert.ToInt32(e.Item.Cells[1].Text); ** does not give any playerID but throws error? How do I get the playerID from GridView. Is the event handler Row Deleting or Row Deleted? Please help............. Sanjeev

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I thought you set up the DataItemIndex on the grid to be a unique ID for that row.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      S 1 Reply Last reply
      0
      • C Christian Graus

        I thought you set up the DataItemIndex on the grid to be a unique ID for that row.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        S Offline
        S Offline
        sanju0276
        wrote on last edited by
        #3

        Hi Christian, Thank you for you reply. I am sorry but I did not understand the reply...... The issue is deleting any row from the grid when gridview is shown in the page. I am trying to programmatically call the delete with code behind. Thank you, Sanjeev. Sanjeev

        C 1 Reply Last reply
        0
        • S sanju0276

          Hi Christian, Thank you for you reply. I am sorry but I did not understand the reply...... The issue is deleting any row from the grid when gridview is shown in the page. I am trying to programmatically call the delete with code behind. Thank you, Sanjeev. Sanjeev

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          A row on a gridview has the property I pointed out, it's purpose is to store a key that you can use to make a database call that identifies that row.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          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