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