By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,234 Members | 1,869 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,234 IT Pros & Developers. It's quick & easy.

Gridview on Delete button and Sorting

P: 5
Hi, I have a problem with my gridview for the deleting and sorting part.
When I try to delete after I sort, it did not delete the correct items that I wanted it to delete.
Can someone help me on this?

Expand|Select|Wrap|Line Numbers
  1. Protected Sub LinkButton1_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
  2.         If e.CommandName = "SortByName" Then
  3.             If Sort = "ASC" Then
  4.                 Sort = "DESC"
  5.             Else
  6.                 Sort = "ASC"
  7.             End If
  8.  
  9.             DataSet.Tables(0).DefaultView.Sort = "Name " & Sort
  10.             Gridview.DataSource = DataSet.Tables(0).DefaultView
  11.             Gridview.DataBind()
  12.  
  13.         End If
  14. End Sub
  15.  
  16. Protected Sub Gridview_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles Gridview.RowDeleting
  17.     Dim name As String = CType(Gridview.Rows(e.RowIndex).FindControl("Label1"), Label).Text
  18.     database.OpenConn()
  19.     Dim strsql As String = "Delete from table where Name = '" & name & "'"
  20.     database.ExecuteUpdate(strsql)
  21.     database.CloseConn()
  22.  
  23. End Sub
  24.  
Apr 25 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.