Editing rows in a GridView
-
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 ?
-
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 ?
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.
-
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.
I am not using any AJAX. the data being returned is not more than 10 rows.