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 and SelectedIndexChanged

GridView and SelectedIndexChanged

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

    Hi!! public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; } This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanks

    S G 2 Replies Last reply
    0
    • F foryou

      Hi!! public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; } This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanks

      S Offline
      S Offline
      Satish Mahapatra
      wrote on last edited by
      #2

      for what purpose ur using the selectionchange event.may be it cant get the template inside the gridview.try it in rowcommand event i think it will work

      1 Reply Last reply
      0
      • F foryou

        Hi!! public void GridView2_SelectedIndexChanged(Object sender, EventArgs e) { TextBox tb = GridView2.SelectedRow.FindControl("id0") as TextBox; if (tb != null) TextBox1.Text = tb.Text; else TextBox1.Text = "no data"; //TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; } This code returns me always "no data" even if there is data in the GridView. I do not see where is the error. thanks

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

        Try debugging, that helps. I guess the .FindControl is not finding your "id0", and for a reason. Imagine you're looking for something, but it's there in front of you, just locked in a box. Your textbox is in a cell of your .SelectedRow, now I can only assume by your commented-out code it's the first cell. so do:

        TextBox tb = GridView2.SelectedRow.Cells[1].FindControl("id0") as TextBox;

        and it should be fine.

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

        F 1 Reply Last reply
        0
        • G Greg Chelstowski

          Try debugging, that helps. I guess the .FindControl is not finding your "id0", and for a reason. Imagine you're looking for something, but it's there in front of you, just locked in a box. Your textbox is in a cell of your .SelectedRow, now I can only assume by your commented-out code it's the first cell. so do:

          TextBox tb = GridView2.SelectedRow.Cells[1].FindControl("id0") as TextBox;

          and it should be fine.

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

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

          Thank you Satish Mahapatra and Greg Chelstowski. I tried your solution but it does not work:( I want to have: the value of a cell of selected line in a GridView. I read that i can do that :TextBox1.Text = GridView2.SelectedRow.Cells[1].Text; but it doesn't work.

          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