Asp.net gridview control edit update cancel commands using vb




















IsPostBack Then ' Create a new table. Add tableRow Next 'Persist the table in the Session object. Rows e. RowIndex dt. Rows row. Controls 0 , TextBox. Text dt. Controls 0 , CheckBox. Checked 'Reset the edit index. Vinu Vasahan Vinu Vasahan 1. The code is: Imports System Imports System.

Data Imports System. Object, ByVal e As System. EventArgs Handles MyBase. Load DataGridView1. ExecuteReader If conreader. Item 0, i. Item 1, i. Item 2, i. Item 3, i. Item 4, i. Item 5, i. Text concmd. Clear End Sub End Class. Ilya Chumakov Use looping and parameter to handle sql injection : con. Cells "Salary". Cells "Experience". DataBind ;. If Not Me. IsPostBack Then. End If. End Sub. Private Sub BindGrid. ConnectionStrings "constr". Using con As New SqlConnection constr.

Using dt As New DataTable. Fill dt. End Using. CustomerId which is the primary key is fetched from the DataKey property of GridView while the Name and Country fields are fetched from their respective columns by referencing the TextBoxes in it.

Finally an Update query is executed over the database table. ToInt32 GridView1. Values[0] ;. Controls[0] as TextBox. AddWithValue " Name" , name ;. AddWithValue " Country" , country ;. Open ;. ExecuteNonQuery ;. Close ;. Rows e. DataKeys e. Values 0. Cells 2. Controls 0 , TextBox. Cells 3. The below is my connection string which is stored in web. You can change this connection string according to your SQL server database setting.

Connection String of Database Data Imports System. Configuration Imports System. Collections Imports System. Web Imports System. Security Imports System. UI Imports System.

WebControls Imports System. WebParts Imports System. HtmlControls Imports System. EventArgs Handles GridView1. Load If Not Page.



0コメント

  • 1000 / 1000