hi
I am doing a project in asp.net with c#. Can anybody help me to edit data in the gridview. How can i enable the cells in gridview to modify the data.

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Security
Imports System.Web.SessionState

Partial Class Edit
    Inherits System.Web.UI.Page
    
    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim objCommand As New SqlCommand()
        objConnection.ConnectionString = ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
        objCommand.CommandText = "UPDATE Company SET CompanyName=@CompanyName,ContactName=@ContactName,ContactTitle=@ContactTitle,Address=@Address,City=@City,Region=@Region,PostalCode=@PostalCode,Country=@Country,Phone=@Phone,Fax=@Fax WHERE USERNAME=@UserName"
        objCommand.Parameters.AddWithValue("@UserName", User.Identity.Name)
        objCommand.Parameters.AddWithValue("@CustomerID", txtID.Text)
        objCommand.Parameters.AddWithValue("@CompanyName", (txtCompany.Text).Trim)
        objCommand.Parameters.AddWithValue("@ContactName", (txtContact.Text).Trim)
        objCommand.Parameters.AddWithValue("@ContactTitle", (txtContactTitle.Text).Trim)
        objCommand.Parameters.AddWithValue("@Address", (txtAddress.Text).Trim)
        objCommand.Parameters.AddWithValue("@City", (txtCity.Text).Trim)
        objCommand.Parameters.AddWithValue("@Region", (txtRegion.Text).Trim)
        objCommand.Parameters.AddWithValue("@PostalCode", (txtPostalCode.Text).Trim)
        objCommand.Parameters.AddWithValue("@Country", (txtCountry.Text).Trim)
        objCommand.Parameters.AddWithValue("@Phone", (txtPhone.Text).Trim)
        objCommand.Parameters.AddWithValue("@Fax", (txtFax.Text).Trim)
        objCommand.CommandType = CommandType.Text
        objCommand.Connection = objConnection
        objConnection.Open()
        If Session("Logged_IN").Equals("Yes") Then
            Try
                objCommand.ExecuteNonQuery()
                lblErr.Text = "Profile Updated"
            Catch ex As SqlException
                lblErr.Text = ex.Message
            End Try
        Else

        End If
        

    End Sub

   
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.