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. value of a cell of selected row

value of a cell of selected row

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

    Hi. For a GridView, how to retrieve the cell values of a selected row? Thank you!

    G 1 Reply Last reply
    0
    • F foryou

      Hi. For a GridView, how to retrieve the cell values of a selected row? Thank you!

      G Offline
      G Offline
      Greg Chelstowski
      wrote on last edited by
      #2

      You asked this question before and I gave you the answer. The reason why it could not have worked for you is most likely your setting a row's state as Selected wrong. My question therefore: how do you select the row, in other words, what code do you exectue in the application, so that it recognizes your desired row as .SelectedRow. Looking at it very hard or highlighting is not the right way. Usually, where you actually do Select a row, getting data from it is really, really easy.

      string something = Gridview1.SelectedRow.Cells[0].Text;

      Honestly, do post some more information, maybe some code of your own if you want people's replies to be relevant.

      var question = (_2b || !(_2b));

      F 1 Reply Last reply
      0
      • G Greg Chelstowski

        You asked this question before and I gave you the answer. The reason why it could not have worked for you is most likely your setting a row's state as Selected wrong. My question therefore: how do you select the row, in other words, what code do you exectue in the application, so that it recognizes your desired row as .SelectedRow. Looking at it very hard or highlighting is not the right way. Usually, where you actually do Select a row, getting data from it is really, really easy.

        string something = Gridview1.SelectedRow.Cells[0].Text;

        Honestly, do post some more information, maybe some code of your own if you want people's replies to be relevant.

        var question = (_2b || !(_2b));

        F Offline
        F Offline
        foryou
        wrote on last edited by
        #3

        Thank you Greg Chelstowski; I tried your code and there:

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
        GridViewRow row = GridView1.Rows[GridView1.SelectedIndex];
        string strValCell = row.Cells[2].Text;
        }

        //and

        public void GridView1_SelectedIndexChanged(Object sender, EventArgs e)
        {

            TextBox1.Text = GridView1.SelectedRow.Cells\[2\].Text; 
        }  
        

        but it doesn't work " any result" and if i do

        public void GridView2_SelectedIndexChanged(Object sender, EventArgs e)
        {
        TextBox tb = GridView1.SelectedRow.FindControl("id0") as TextBox;
        if (tb != null)

             TextBox1.Text = tb.Text;
        
            else
               TextBox1.Text = "no data";
           
        }
        

        I have always "no data"

        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