Go4Expert

Go4Expert (http://www.go4expert.com/)
-   ASP (http://www.go4expert.com/forums/asp/)
-   -   how to delete a row in a gridview (http://www.go4expert.com/forums/delete-row-gridview-t20472/)

shyam_oec 22Dec2009 19:45

how to delete a row in a gridview
 
hi,
in a grid view i have enabled delete link,so that when a user clicks a delete link,corresponding row gets deleted from the database as well as from grid view.Data in the grid view is filled through coding,in the program using DataAdapter.
So, how to do that?

nimesh 25Dec2009 11:36

Re: how to delete a row in a gridview
 
This is the code that I've used in my program for this purpose.

Code: vb

Protected Sub DeleteSQLCode(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim lnkRemove As LinkButton = DirectCast(sender, LinkButton)
            strSql = "delete from myreports where ID = @id"
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("./App_Data/Reports.mdb") & ";User Id=admin;Password=;")
            com = New OleDbCommand(strSql, con)
            com.CommandText = strSql
            com.CommandType = CommandType.Text
            com.Parameters.Add("@id", OleDbType.Integer).Value = lnkRemove.CommandArgument
            com.Connection.Open()
            com.ExecuteNonQuery()
            com.Connection.Close()
            disp_myrep()
        Catch
            msg = "<h1 class=""ErrMsg"">Error Encountered: </h1>" & "<br/><b><font color=""red"">Error Source: " & Err.Source & "<br/>Error Description: " & Err.Description & "</font></b>"
        End Try
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
    End Sub


nimesh 25Dec2009 13:21

Re: how to delete a row in a gridview
 
I referred this page for gridview operations. But still stuck on Edit Record.
http://www.aspsnippets.com/post/2009...-AJAX-way.aspx


All times are GMT +5.5. The time now is 19:15.