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. Getting ColumnID Value from GridView? [modified]

Getting ColumnID Value from GridView? [modified]

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............. :confused: -- modified at 16:34 Wednesday 27th September, 2006

    Sanju

    D 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............. :confused: -- modified at 16:34 Wednesday 27th September, 2006

      Sanju

      D Offline
      D Offline
      dgonzale
      wrote on last edited by
      #2

      could you please post the error message you're getting?

      S 1 Reply Last reply
      0
      • D dgonzale

        could you please post the error message you're getting?

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

        Thanks for you immediate reply........ Here is the error !!! 'System.Web.UI.WebControls.GridViewDeleteEventArgs' does not contain a definition for 'Item' How do I retrieve PlayerID from the GridView? Thanks

        Sanjeev

        D 1 Reply Last reply
        0
        • S sanju0276

          Thanks for you immediate reply........ Here is the error !!! 'System.Web.UI.WebControls.GridViewDeleteEventArgs' does not contain a definition for 'Item' How do I retrieve PlayerID from the GridView? Thanks

          Sanjeev

          D Offline
          D Offline
          dgonzale
          wrote on last edited by
          #4

          San, that is weird, it is the sam way I do it (in VB.net) under the DataGrid Delete or Edit item methods (ASP.NET 1.1) , honestly I never worked with an ASP.NET 2.0 GridView object before. Sorry! :(

          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