Row Deleting Event in ASP.NET

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
Conn.ConnectionString = Connection1.ConnectionString
Dim cmd As New SqlCommand(“delete from [pengguna] where kode_pengguna='” & GridView1.DataKeys(e.RowIndex).Value.ToString() & “‘”, Conn)
Conn.Open()
cmd.ExecuteNonQuery()
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
Conn.Close()
End Sub

Row deleting di ASP.NET, jika ingin menggunakan button deleting pada gridview, tambahkan event RowDeleting pada gridview yang anda buat. Jangan lupa buat datakeys pada properties gridview. Lebih baik gunakan nama column sebagai datakeys untuk mempermudah…atau mungkin memang seharusnya nama kolom…hhahahha…maklum…sama-sama newbie banged nie…😀

contoh2

Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting

Conn.ConnectionString = Connection1.ConnectionString

Dim cmd As New SqlCommand(“delete from [pengguna] where kode_pengguna='” & GridView1.DataKeys(e.RowIndex).Value.ToString() & “‘”, Conn)

//GridView1.DataKeys(e.RowIndex).Value.ToString() digunakan untuk //mengambil value datakeys dari row yang dipilih

Conn.Open()

cmd.ExecuteNonQuery()

GridView1.DataSource = SqlDataSource1

GridView1.DataBind()

Conn.Close()

End Sub

2 comments

  1. ian · October 29, 2009

    kolo nambahin konfirmasi delete nya gimana??🙂

    • lia1488 · November 1, 2009

      nah…itu dia…lom bisa…wkwkwkwkwk….
      kayanya harus pake javascript…tapi da lum ahli…. :p
      tar deh, kalo uda ketemu di post….😀

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s