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. Editing rows in a GridView

Editing rows in a GridView

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

    I have a gridview that is being dynamically populated with data based on textbox values at runtime. The code inside the button click is as follows:- 1 conn.Open(); 2 string strSQL = "SELECT [UserId], [IsLockedOut] FROM [ac_Users] WHERE ([UserId] =" + Int32.Parse(tb_UserID.Text) + ")"; 3 SqlCommand cmd = new SqlCommand(strSQL, conn); 4 DataTable dt = new DataTable(); 5 SqlDataAdapter sqlAdapter = new SqlDataAdapter(null, conn); 6 sqlAdapter.SelectCommand = cmd; 7 sqlAdapter.Fill(dt); 8 conn.Close(); 9 try 10 { 11 grd_Users.DataSource = dt.DefaultView; 12 grd_Users.DataBind(); 13 pnl_Users.Visible = true; 14 } 15 catch (Exception ex) 16 { 17 TestUtils2.TestLogger.WriteErrorEntry(ex.Message, AuctivaUtils2.eAuctivaLogFile.General); 18 } 19 finally 20 { 21 conn.Close(); 22 } The gridview is correctly populated with the data I need, however I want each row in the data that is returned to be editable. I have the AutoGenerateEditButton property set to true and have also set the DataKeys property of the the gridview with the primary key of the table being returned. However when I click the 'edit" link that appears in each row in the gridview, nothing happens. How do I make that button make the corresponding row editable ?

    J 1 Reply Last reply
    0
    • C Cyberpulse

      I have a gridview that is being dynamically populated with data based on textbox values at runtime. The code inside the button click is as follows:- 1 conn.Open(); 2 string strSQL = "SELECT [UserId], [IsLockedOut] FROM [ac_Users] WHERE ([UserId] =" + Int32.Parse(tb_UserID.Text) + ")"; 3 SqlCommand cmd = new SqlCommand(strSQL, conn); 4 DataTable dt = new DataTable(); 5 SqlDataAdapter sqlAdapter = new SqlDataAdapter(null, conn); 6 sqlAdapter.SelectCommand = cmd; 7 sqlAdapter.Fill(dt); 8 conn.Close(); 9 try 10 { 11 grd_Users.DataSource = dt.DefaultView; 12 grd_Users.DataBind(); 13 pnl_Users.Visible = true; 14 } 15 catch (Exception ex) 16 { 17 TestUtils2.TestLogger.WriteErrorEntry(ex.Message, AuctivaUtils2.eAuctivaLogFile.General); 18 } 19 finally 20 { 21 conn.Close(); 22 } The gridview is correctly populated with the data I need, however I want each row in the data that is returned to be editable. I have the AutoGenerateEditButton property set to true and have also set the DataKeys property of the the gridview with the primary key of the table being returned. However when I click the 'edit" link that appears in each row in the gridview, nothing happens. How do I make that button make the corresponding row editable ?

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      You should probably drop the line numbers and wrap your code in

      ...makes it easier to read. As for why edit doesn't work...I'd need to know more. Are you using an UpdatePanel/AJAX? How much data is bing bound? A few rows, or thousands? Volume can affect the performance of actions like edit sometimes.

      C 1 Reply Last reply
      0
      • J Jon Rista

        You should probably drop the line numbers and wrap your code in

        ...makes it easier to read. As for why edit doesn't work...I'd need to know more. Are you using an UpdatePanel/AJAX? How much data is bing bound? A few rows, or thousands? Volume can affect the performance of actions like edit sometimes.

        C Offline
        C Offline
        Cyberpulse
        wrote on last edited by
        #3

        I am not using any AJAX. the data being returned is not more than 10 rows.

        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