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. Update rows in a gridview

Update rows in a gridview

Scheduled Pinned Locked Moved ASP.NET
designhelpquestionannouncement
2 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 I am populating with data based on user values in a textbox from the code behind. I have the gridview working correctly upto the point of displaying relevant data, making the selected row editable when the 'edit' link next to the corresponding row is clicked and cancelling the editable row so that reverts back to display mode. The problem is updating. How do I save the changes made to a specific row in edit mode once I hit the update link. My code is as follows:- 1 public partial class UserLockouts : System.Web.UI.Page 2 { 3 public SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xyz"].ConnectionString); 4 public static int uniqueStoreId = 0; 5 public static int storeId = 0; 6 public static int userId = 0; 7 protected void Page_Load(object sender, EventArgs e) 8 { 9 10 } 11 12 protected void btn_Search_Click(object sender, EventArgs e) 13 { 14 bindGridView(); 15 } 16 17 protected void bindGridView() 18 { 19 if (tb_UniqueSN.Text != string.Empty) 20 { 21 conn.Open(); 22 string strSQL = "SELECT [StoreId] FROM [ac_StoreSettings] WHERE ([FieldValue] ='" + tb_UniqueSN.Text + "')"; 23 SqlCommand cmd = new SqlCommand(strSQL, conn); 24 Object myData = cmd.ExecuteScalar(); 25 uniqueStoreId = Int32.Parse(myData.ToString()); 26 storeId = uniqueStoreId; 27 conn.Close(); 28 } 29 30 else if (tb_StoreID.Text != string.Empty) 31 { 32 storeId = Int32.Parse(tb_StoreID.Text); 33 } 34 35 else if (tb_UserID.Text != string.Empty) 36 { 37 conn.Open(); 38 string strSQL = "SELECT [UserId], [IsLockedOut] FROM [ac_Users] WHERE ([UserId] =" + Int32.Parse(tb_UserID.Text) + ")"; 39 SqlCommand cmd = new SqlCommand(strSQL, conn); 40 DataTable dt = new DataTable(); 41 SqlDataAdapter sqlAdapter = new SqlDataAdapter(null, conn); 42 sqlAdapter.SelectCommand = cmd; 43 sqlAdapter.Fill(dt); 44 conn.Close(); 45 try 46 { 47 grd_Users.Data

    N 1 Reply Last reply
    0
    • C Cyberpulse

      I have a gridview that I am populating with data based on user values in a textbox from the code behind. I have the gridview working correctly upto the point of displaying relevant data, making the selected row editable when the 'edit' link next to the corresponding row is clicked and cancelling the editable row so that reverts back to display mode. The problem is updating. How do I save the changes made to a specific row in edit mode once I hit the update link. My code is as follows:- 1 public partial class UserLockouts : System.Web.UI.Page 2 { 3 public SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xyz"].ConnectionString); 4 public static int uniqueStoreId = 0; 5 public static int storeId = 0; 6 public static int userId = 0; 7 protected void Page_Load(object sender, EventArgs e) 8 { 9 10 } 11 12 protected void btn_Search_Click(object sender, EventArgs e) 13 { 14 bindGridView(); 15 } 16 17 protected void bindGridView() 18 { 19 if (tb_UniqueSN.Text != string.Empty) 20 { 21 conn.Open(); 22 string strSQL = "SELECT [StoreId] FROM [ac_StoreSettings] WHERE ([FieldValue] ='" + tb_UniqueSN.Text + "')"; 23 SqlCommand cmd = new SqlCommand(strSQL, conn); 24 Object myData = cmd.ExecuteScalar(); 25 uniqueStoreId = Int32.Parse(myData.ToString()); 26 storeId = uniqueStoreId; 27 conn.Close(); 28 } 29 30 else if (tb_StoreID.Text != string.Empty) 31 { 32 storeId = Int32.Parse(tb_StoreID.Text); 33 } 34 35 else if (tb_UserID.Text != string.Empty) 36 { 37 conn.Open(); 38 string strSQL = "SELECT [UserId], [IsLockedOut] FROM [ac_Users] WHERE ([UserId] =" + Int32.Parse(tb_UserID.Text) + ")"; 39 SqlCommand cmd = new SqlCommand(strSQL, conn); 40 DataTable dt = new DataTable(); 41 SqlDataAdapter sqlAdapter = new SqlDataAdapter(null, conn); 42 sqlAdapter.SelectCommand = cmd; 43 sqlAdapter.Fill(dt); 44 conn.Close(); 45 try 46 { 47 grd_Users.Data

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Cyberpulse wrote:

      How do I save the changes made to a specific row in edit mode once I hit the update link.

      You need to handle that event. Write queries to update the database and renind the grid. Since you are new to CP, when you post code, try to wrap it in <pre></pre> tags and indent the lines. The code which you posted in less readable.

      Navaneeth How to use google | Ask smart questions

      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