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. Unable to set focus to a text box contained in a gridview's row cell after post-back and binding.

Unable to set focus to a text box contained in a gridview's row cell after post-back and binding.

Scheduled Pinned Locked Moved ASP.NET
wpfwcfquestion
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.
  • S Offline
    S Offline
    Steve Holdorf
    wrote on last edited by
    #1

    I have a gridview that contains rows where each row's cell contains a textbox. After inserting a new row into the gridview I want the new row's first textbox to have the focus. I have tried verious ways to set the new row first cell's textbox to have the focus but am unable. Does anyone know how this is done? Thanks, Steve

    M B 2 Replies Last reply
    0
    • S Steve Holdorf

      I have a gridview that contains rows where each row's cell contains a textbox. After inserting a new row into the gridview I want the new row's first textbox to have the focus. I have tried verious ways to set the new row first cell's textbox to have the focus but am unable. Does anyone know how this is done? Thanks, Steve

      M Offline
      M Offline
      Masood Kochi SSF
      wrote on last edited by
      #2

      Send your .focus() code

      S 1 Reply Last reply
      0
      • S Steve Holdorf

        I have a gridview that contains rows where each row's cell contains a textbox. After inserting a new row into the gridview I want the new row's first textbox to have the focus. I have tried verious ways to set the new row first cell's textbox to have the focus but am unable. Does anyone know how this is done? Thanks, Steve

        B Offline
        B Offline
        boy pockets
        wrote on last edited by
        #3

        My first thought would be to find the row that it is in Insert mode (SelectedRow maybe) and give it focus. My second thought would be to extend the GridView in a Server Control. Override the Focus() method. In this method, if the GridView is in insert mode (GridView.CurrentMode), then get the current row (SelectedRow) and then set the focus to that row. If the GridView is not in insert mode than just pass the call to the base (base.Focus()).

        1 Reply Last reply
        0
        • M Masood Kochi SSF

          Send your .focus() code

          S Offline
          S Offline
          Steve Holdorf
          wrote on last edited by
          #4

          Here is the code I am trying:

          protected void GridViewCollectionManagement_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (e.Row.RowIndex == focus) { // TextBox tb = (TextBox)e.Row.Cells[0].Controls[1]; // this.SetFocus(tb); DefaultFocus = ((TextBox)e.Row.FindControl ("newCollectionName")).ClientID; }

          One thing to note is that this gridview is contained in a ajax panel and is a content page of a master page.

          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