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. Index was out of range. Must be non-negative and less than the size of the collection.

Index was out of range. Must be non-negative and less than the size of the collection.

Scheduled Pinned Locked Moved ASP.NET
helpcssdatabase
5 Posts 3 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.
  • R Offline
    R Offline
    reogeo2008
    wrote on last edited by
    #1

    Hi all, Below is my gridview This is the code for deleting a row protected void bcgrid_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(bcgrid.DataKeys[e.RowIndex].Values[0].ToString()); Delete(id); } I am getting the error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Can anybody help me in come out of this error Thanks in Advance

    B A 2 Replies Last reply
    0
    • R reogeo2008

      Hi all, Below is my gridview This is the code for deleting a row protected void bcgrid_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(bcgrid.DataKeys[e.RowIndex].Values[0].ToString()); Delete(id); } I am getting the error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Can anybody help me in come out of this error Thanks in Advance

      B Offline
      B Offline
      Brij
      wrote on last edited by
      #2

      At which line you are getting error?The error says,that the id doesn't fall in index range vailable.Debug the code and check the id and available index range.

      Cheers!! Brij

      R 1 Reply Last reply
      0
      • B Brij

        At which line you are getting error?The error says,that the id doesn't fall in index range vailable.Debug the code and check the id and available index range.

        Cheers!! Brij

        R Offline
        R Offline
        reogeo2008
        wrote on last edited by
        #3

        int id = Convert.ToInt32(bcgrid.DataKeys[e.RowIndex].Values[0].ToString()); ths line gives error

        B 1 Reply Last reply
        0
        • R reogeo2008

          int id = Convert.ToInt32(bcgrid.DataKeys[e.RowIndex].Values[0].ToString()); ths line gives error

          B Offline
          B Offline
          Brij
          wrote on last edited by
          #4

          Check the length of the collection bcgrid.DataKeys and bcgrid.DataKeys[e.RowIndex].Values and accordingly check the index

          Cheers!! Brij

          1 Reply Last reply
          0
          • R reogeo2008

            Hi all, Below is my gridview This is the code for deleting a row protected void bcgrid_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32(bcgrid.DataKeys[e.RowIndex].Values[0].ToString()); Delete(id); } I am getting the error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Can anybody help me in come out of this error Thanks in Advance

            A Offline
            A Offline
            Ashok Login
            wrote on last edited by
            #5

            In the code-behind, you are using DataKeyItem's Index, but you are not telling to the program what datakeys are. For the GridView control, you have to specify DataKeyNames property.

            Ashok kumar.

            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