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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Problem with gridview checkbox [modified]

Problem with gridview checkbox [modified]

Scheduled Pinned Locked Moved ASP.NET
helpcssdatabase
6 Posts 4 Posters 1 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.
  • P Offline
    P Offline
    pinna_hari
    wrote on last edited by
    #1

    Hello, I have a gridview with checkboxes(inside Gridview) and a Button contol(outside of Gridview)with BtnDeleteSelected My aim is to get the value of 1st row 2nd column in gridview(1st Column is CheckBox control) and 2nd column is pid value.I want 'Pid' Value i wrote this code int pID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Value); it is showing this error

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

    Pinna

    modified on Thursday, May 22, 2008 9:15 AM

    N E 2 Replies Last reply
    0
    • P pinna_hari

      Hello, I have a gridview with checkboxes(inside Gridview) and a Button contol(outside of Gridview)with BtnDeleteSelected My aim is to get the value of 1st row 2nd column in gridview(1st Column is CheckBox control) and 2nd column is pid value.I want 'Pid' Value i wrote this code int pID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Value); it is showing this error

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

      Pinna

      modified on Thursday, May 22, 2008 9:15 AM

      N Offline
      N Offline
      NetBot
      wrote on last edited by
      #2

      haripinna wrote:

      GridViewRow row = gv.Rows[i]; CheckBox chkbox = (CheckBox)row.FindControl("chkSelect")

      Oh what code have u posted. I can`t get head or tails out of it..Pls post the entire code so that we can understand your logic implementation.

      P 1 Reply Last reply
      0
      • P pinna_hari

        Hello, I have a gridview with checkboxes(inside Gridview) and a Button contol(outside of Gridview)with BtnDeleteSelected My aim is to get the value of 1st row 2nd column in gridview(1st Column is CheckBox control) and 2nd column is pid value.I want 'Pid' Value i wrote this code int pID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Value); it is showing this error

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

        Pinna

        modified on Thursday, May 22, 2008 9:15 AM

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #3

        at the moment you are only finding the checkbox Wheres the code which should be setting the checkbox to true or false Can you explain a bit more?

        1 Reply Last reply
        0
        • N NetBot

          haripinna wrote:

          GridViewRow row = gv.Rows[i]; CheckBox chkbox = (CheckBox)row.FindControl("chkSelect")

          Oh what code have u posted. I can`t get head or tails out of it..Pls post the entire code so that we can understand your logic implementation.

          P Offline
          P Offline
          pinna_hari
          wrote on last edited by
          #4

          Hello, Thanks for your response. I got answer for that question.. now my problem is I have a gridview with checkboxes(inside Gridview) and a Button control(outside of Gridview)with BtnDeleteSelected My aim is to get the value of 1st row 2nd column of gridview(1st Column is CheckBox control) and 2nd column is pid value.I want 'Pid' Value i wrote this code

          for(i=0;i
          {
          GridViewRow row = gv.Rows[i];
          CheckBox chkbox = (CheckBox)row.FindControl("chkSelect")
          if(chkbox.checked)
          {
          int pID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Value);
          }
          }

          it is showing this error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

          Pinna

          S 1 Reply Last reply
          0
          • P pinna_hari

            Hello, Thanks for your response. I got answer for that question.. now my problem is I have a gridview with checkboxes(inside Gridview) and a Button control(outside of Gridview)with BtnDeleteSelected My aim is to get the value of 1st row 2nd column of gridview(1st Column is CheckBox control) and 2nd column is pid value.I want 'Pid' Value i wrote this code

            for(i=0;i
            {
            GridViewRow row = gv.Rows[i];
            CheckBox chkbox = (CheckBox)row.FindControl("chkSelect")
            if(chkbox.checked)
            {
            int pID = Convert.ToInt32(gv.DataKeys[row.RowIndex].Value);
            }
            }

            it is showing this error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

            Pinna

            S Offline
            S Offline
            sukkureddy
            wrote on last edited by
            #5

            Try this string strContactId = "" + gvContacts.SelectedDataKey["ContactId"]; or string strContactId = "" + gvContacts.SelectedValue; You have to write these Code in OnSelectedIndexChanged event of gridview.Initially you have to set Datakeynames="ContactId" in gridview property. i hope it wil work for u

            P 1 Reply Last reply
            0
            • S sukkureddy

              Try this string strContactId = "" + gvContacts.SelectedDataKey["ContactId"]; or string strContactId = "" + gvContacts.SelectedValue; You have to write these Code in OnSelectedIndexChanged event of gridview.Initially you have to set Datakeynames="ContactId" in gridview property. i hope it wil work for u

              P Offline
              P Offline
              pinna_hari
              wrote on last edited by
              #6

              Thanks..got it..

              Pinna

              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