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 selected index returns -1 out of range exception

gridview selected index returns -1 out of range exception

Scheduled Pinned Locked Moved ASP.NET
database
4 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.
  • T Offline
    T Offline
    tejesh123
    wrote on last edited by
    #1

    hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh

    P T 2 Replies Last reply
    0
    • T tejesh123

      hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh

      P Offline
      P Offline
      Piyush Vardhan Singh
      wrote on last edited by
      #2

      it should be help u or u pass incorrect control name chkSelect # foreach (GridViewRow row in uxgridAllActivities.Rows) { # //' Access the CheckBox # CheckBox cb = (CheckBox)row.FindControl("chkSelect");

      Piyush Vardhan Singh p_vardhan14@rediffmail.com http://holyschoolofvaranasi.blogspot.com http://holytravelsofvaranasi.blogspot.com

      T 1 Reply Last reply
      0
      • T tejesh123

        hi all I am trying to write a code wherein when user click on the row the particular checkbox will be checked/unchecked. My code for this is CheckBox cb = (CheckBox)GridView1.Rows[selectedindex].FindControl("checked"); which returns -1; Please suggest soln to it. Tejesh

        T Offline
        T Offline
        ToddHileHoffer
        wrote on last edited by
        #3

        First of all what type of control is causing the postback? I'm going to assume it is a button. Button ButtonClicked = (Button)sender; GridViewRow gvr = (GridviewRow)ButtonClicked.namingContainer; CheckBox cb = (CheckBox) gvr.findcontrol("cbId"); cb.checked = true;

        I didn't get any requirements for the signature

        1 Reply Last reply
        0
        • P Piyush Vardhan Singh

          it should be help u or u pass incorrect control name chkSelect # foreach (GridViewRow row in uxgridAllActivities.Rows) { # //' Access the CheckBox # CheckBox cb = (CheckBox)row.FindControl("chkSelect");

          Piyush Vardhan Singh p_vardhan14@rediffmail.com http://holyschoolofvaranasi.blogspot.com http://holytravelsofvaranasi.blogspot.com

          T Offline
          T Offline
          tejesh123
          wrote on last edited by
          #4

          Hi Thx for the Reply protected void grid_row_command(object sender, GridViewCommandEventArgs e) { GridView g = (GridView)sender; int selectedindex = g.SelectedIndex; string commandname = e.CommandName; switch (commandname) { case ("singleclick"): // Response.Write("Single Click"); CheckBox cb = (CheckBox)g.Rows[selectedindex].FindControl("checked"); if (cb.Checked) cb.Checked = false; else cb.Checked = true; break; case ("doubleclick") : Response.Write("DoubleClcik"); break; } } i am trying to write the set the selected index on OnRowCommand="grid_row_command" for my gridview I dont know where i am going wrong.. Waiting for reply

          modified on Friday, January 9, 2009 12:10 AM

          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