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. Accessing a particular cells Address on click in a gridview

Accessing a particular cells Address on click in a gridview

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netquestion
6 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
    sangramkp
    wrote on last edited by
    #1

    Hi, I want to access the cells address of a gridview control on click or double click... In Windows application with DatagridView it's quite easy.. How can i get the same in asp.net gridview control

    Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

    S 1 Reply Last reply
    0
    • S sangramkp

      Hi, I want to access the cells address of a gridview control on click or double click... In Windows application with DatagridView it's quite easy.. How can i get the same in asp.net gridview control

      Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      what you are trying to do? if you want to postback the page then you can achieve this by adding the following attribute in RowDataBound of the gridview: foreach TableCell cell in curRow.Cells { cell.Attributes.Add("id",cell.ClientID); cell.Attributes.Add("onclick", "javascript:document.formname.submit();"); } in the event handler for the cell you can get the ID of the sender; and if you want to do something on client side using javascript then do this: foreach TableCell cell in curRow.Cells { cell.Attributes.Add("id",cell.ClientID); cell.Attributes.Add("onclick", "javascript:getTheCell(this);"); } and in javascript file do this: function getTheCell(cell) { alert('You clicked cell ID: '+ cell.ID); }

      -----

      S 1 Reply Last reply
      0
      • S SABhatti

        what you are trying to do? if you want to postback the page then you can achieve this by adding the following attribute in RowDataBound of the gridview: foreach TableCell cell in curRow.Cells { cell.Attributes.Add("id",cell.ClientID); cell.Attributes.Add("onclick", "javascript:document.formname.submit();"); } in the event handler for the cell you can get the ID of the sender; and if you want to do something on client side using javascript then do this: foreach TableCell cell in curRow.Cells { cell.Attributes.Add("id",cell.ClientID); cell.Attributes.Add("onclick", "javascript:getTheCell(this);"); } and in javascript file do this: function getTheCell(cell) { alert('You clicked cell ID: '+ cell.ID); }

        -----

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

        Hi SABhatti, I am preparing a seatlayout type of application using a gridview. i am generating a gridview but i want to store the cells address on click in a listbox or list item and later store them in database... I think i have descibe clearly above.... I am trying using the solution...as u gave But If there a better way or a link where I can refer I will be glad..

        Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

        S 1 Reply Last reply
        0
        • S sangramkp

          Hi SABhatti, I am preparing a seatlayout type of application using a gridview. i am generating a gridview but i want to store the cells address on click in a listbox or list item and later store them in database... I think i have descibe clearly above.... I am trying using the solution...as u gave But If there a better way or a link where I can refer I will be glad..

          Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

          S Offline
          S Offline
          SABhatti
          wrote on last edited by
          #4

          if you are using AJAX then you can even do a partial postback and store that address on the server. But I will suggest the javascript solution I gave you in my previous response. In that javascript function store the ID's in a hidden filed separated by comma and highlight the cells (change the backround color using stylesheet cell.className in javascript). when user submit the form get the clicked cells from hidden field, split them based on , and store them in database.

          -----

          S 1 Reply Last reply
          0
          • S SABhatti

            if you are using AJAX then you can even do a partial postback and store that address on the server. But I will suggest the javascript solution I gave you in my previous response. In that javascript function store the ID's in a hidden filed separated by comma and highlight the cells (change the backround color using stylesheet cell.className in javascript). when user submit the form get the clicked cells from hidden field, split them based on , and store them in database.

            -----

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

            Hi SABhatti, I am trying the solution provided but it's not getting the cellId... It shows in alert; You have clicked the cell: undefined Need urgent help please

            Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

            S 1 Reply Last reply
            0
            • S sangramkp

              Hi SABhatti, I am trying the solution provided but it's not getting the cellId... It shows in alert; You have clicked the cell: undefined Need urgent help please

              Sangram (A battle with self) Life is simple, we are the ones makes the living difficult

              S Offline
              S Offline
              SABhatti
              wrote on last edited by
              #6

              ok are you doing this in rowdatabound of the gridview foreach (TableCell cell in e.Row.Cells) { cell.Attributes.Add("id",cell.ClientID); cell.Attributes.Add("onclick", "javascript:getTheCell(this);"); } and in javascript file do this: // sorry .id is lower case function getTheCell(cell) { alert('You clicked cell ID: '+ cell.id); }

              -----

              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