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. How to access gridview editing row element value in a class function?

How to access gridview editing row element value in a class function?

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

    To access formview editing element in a class function, I can use the following code: HttpContext.Current.Request.Form("fvwName$elmName") How can I access gridview editing row element value in a class function?

    M 1 Reply Last reply
    0
    • J JimFeng

      To access formview editing element in a class function, I can use the following code: HttpContext.Current.Request.Form("fvwName$elmName") How can I access gridview editing row element value in a class function?

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      + Get reference to the Page instance by casting the HttpContext.Current.Handler property to the Page. + Get reference to the GridView control using the Page instance and the FindControl method. + Get reference to the editable row using the properties of the GridView instance that you have in the previous step.

      J 1 Reply Last reply
      0
      • M minhpc_bk

        + Get reference to the Page instance by casting the HttpContext.Current.Handler property to the Page. + Get reference to the GridView control using the Page instance and the FindControl method. + Get reference to the editable row using the properties of the GridView instance that you have in the previous step.

        J Offline
        J Offline
        JimFeng
        wrote on last edited by
        #3

        Could you please post some code sample?

        M 1 Reply Last reply
        0
        • J JimFeng

          Could you please post some code sample?

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Below is the sample code for getting the edit row, and once you have the reference you can easily access the edit values from the cells of the row:

          public GridViewRow GetEditRow()
          {
          Page page = HttpContext.Current.Handler as Page;

              GridView gridView = page.FindControl("GridView1") as GridView;
          
              GridViewRow editRow = gridView.Rows\[gridView.EditIndex\];
          
              return editRow; 
          }
          
          J 1 Reply Last reply
          0
          • M minhpc_bk

            Below is the sample code for getting the edit row, and once you have the reference you can easily access the edit values from the cells of the row:

            public GridViewRow GetEditRow()
            {
            Page page = HttpContext.Current.Handler as Page;

                GridView gridView = page.FindControl("GridView1") as GridView;
            
                GridViewRow editRow = gridView.Rows\[gridView.EditIndex\];
            
                return editRow; 
            }
            
            J Offline
            J Offline
            JimFeng
            wrote on last edited by
            #5

            When I try your code, I got the following error on line GridViewRow editRow = gridView.Rows[gridView.EditIndex]; Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

            M 1 Reply Last reply
            0
            • J JimFeng

              When I try your code, I got the following error on line GridViewRow editRow = gridView.Rows[gridView.EditIndex]; Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

              M Offline
              M Offline
              minhpc_bk
              wrote on last edited by
              #6

              That's because I'm using the Edit built-in button in the GridView control so that when I hit the Edit button, the control's mode is changed to the Edit mode and the EditIndex property is set internally. And when the Update button is clicked, I can access the edit row in a seperate class with the above code. I'm not sure when you want to run that code, but if you use your own button, you can raise the Edit command like the built-in button by setting the CommandName as Edit. You might also try to have a look at the EditIndex value at runtime to diagnose your problem. The basic idea is that you need a way to determine the row that is being edited and the index of the row comes to mind as an option.

              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