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. Grid View Selected Index

Grid View Selected Index

Scheduled Pinned Locked Moved ASP.NET
cssdatabasehelp
3 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.
  • N Offline
    N Offline
    NET India
    wrote on last edited by
    #1

    Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.

    G A 2 Replies Last reply
    0
    • N NET India

      Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.

      G Offline
      G Offline
      Gandalf_TheWhite
      wrote on last edited by
      #2

      HI Knowledge! Actually I m not getting what exactly ur problem lies. Is label inside the Grid or Outside? do ur Source has the Unique Id that u r use to bind the grid? And yes About the Error : This Error Generally Arises when There is Unavailability of a Control.

      Believe Yourself™ :->™

      1 Reply Last reply
      0
      • N NET India

        Hello Friends, I want to get the ID(unique field in "GridView3") respectively i click on the "Select" button or link. Here i'm giving my code. Plz check and make me correct. protected void GridView3_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); } But it throw(s) an error like Object reference not set to an instance of an object.

        A Offline
        A Offline
        amargujrathi2006
        wrote on last edited by
        #3

        This event doesn't give you any selected row,you have to select row of the gridview as GridView3.SelectedIndex=e.NewSelectedIndex; GridView3.datasource=place here datatable GridView3.databind() place ur code in the following event. I think your problem will be solved. protected void GridView3_SelectedIndexChanged(object sender, EventArgs e) { string str = GridView3.SelectedRow.Cells[1].Text; lblMsg.Text = str.ToString(); OR lblMsg.Text = GridView3.SelectedRow.RowIndex.ToString(); }

        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