943,790 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 437
  • ASP.NET RSS
Sep 25th, 2009
0

Take the ID Line GridView popular handbook

Expand Post »
Hello Friends

I still muddled with some things (that is with a lot of them). I have a Gridview, where the first column ia a TemplateField with a LinkButton to delete the record, the selected row.

I did the same routine using the primary key with DataKeyNames, however in this case the GridView, was populated manually and now I'm using curl.

I did the following:

ASP.NET Syntax (Toggle Plain Text)
  1. Protected Sub GrdDocumentos_RowDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdDocumentos.RowDataBound
  2.  
  3. If e.Row.RowType = DataControlRowType.DataRow Then
  4. Dim l As LinkButton = DirectCast (e.Row.FindControl ( "LinkButton1"), LinkButton)
  5. l.Attributes.Add ( "onclick", ( "javascript: return" & "confirm ( 'Really delete the Document") & DataBinder.Eval (e.Row.DataItem, "REL_DOCUMENTO") & "?')")
  6. End If
  7. End Sub

ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub GrdDocumentos_RowCommand (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GrdDocumentos.RowCommand
  2. 'Can I exclude here in RowCommand
  3.  
  4. If e.CommandName = "Delete" Then
  5. RelID GrdDocumentos.SelectedRow.Cells = (4). Text (does not work that way)
  6.  
  7. 'GrdDocumentos.SelectedIndex = SelectedGridRow.RowIndex
  8. 'Delete the record
  9. 'Implement this on your own:)
  10. DeleteRecordByID (relID)
  11. End If
  12. End Sub

ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub DeleteRecordByID (ByVal RegID As Integer)
  2.  
  3. Dim Sql As String
  4. Dim cmd As SqlCommand
  5.  
  6. Dim connection As SqlConnection
  7.  
  8. connection = New SqlConnection (ConfigurationManager.ConnectionStrings ( "Timesheet"). ConnectionString)
  9.  
  10. Sql = "DELETE FROM REL_PROJETOS"
  11. Sql + = "WHERE REL_ID =" & RegID
  12.  
  13. cmd = New SqlCommand (Sql, connection)
  14.  
  15. Try
  16. conexao.Open ()
  17.  
  18. cmd.Connection = connection
  19.  
  20. cmd.CommandType = CommandType.Text
  21.  
  22. cmd.CommandText = Sql
  23.  
  24. cmd.ExecuteNonQuery ()
  25. Catch ex As Exception
  26. lblMensagem.Text = "Error Occurred While Deleting:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString
  27. Finally
  28. conexao.Close ()
  29. GrdDocumentos.DataBind ()
  30. End Try
  31. End Sub Protected Sub GrdDocumentos_SelectedIndexChanging (ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged
  32. RelID = GrdDocumentos.SelectedRow.Cells (12). Text
  33. End Sub
  34.  

Then I need to get the ID to be able to delete the desired record.

Thanks and a hug
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
SID.SIL is offline Offline
28 posts
since Mar 2009
Sep 28th, 2009
0

Re: Take the ID Line GridView popular handbook

Click to Expand / Collapse  Quote originally posted by SID.SIL ...
Hello Friends

I still muddled with some things (that is with a lot of them). I have a Gridview, where the first column ia a TemplateField with a LinkButton to delete the record, the selected row.

I did the same routine using the primary key with DataKeyNames, however in this case the GridView, was populated manually and now I'm using curl.

I did the following:

ASP.NET Syntax (Toggle Plain Text)
  1. Protected Sub GrdDocumentos_RowDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdDocumentos.RowDataBound
  2.  
  3. If e.Row.RowType = DataControlRowType.DataRow Then
  4. Dim l As LinkButton = DirectCast (e.Row.FindControl ( "LinkButton1"), LinkButton)
  5. l.Attributes.Add ( "onclick", ( "javascript: return" & "confirm ( 'Really delete the Document") & DataBinder.Eval (e.Row.DataItem, "REL_DOCUMENTO") & "?')")
  6. End If
  7. End Sub

 Private Sub  GrdDocumentos_RowCommand (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GrdDocumentos.RowCommand 
         'Can I exclude here in RowCommand 

         If e.CommandName = "Delete" Then 
              RelID GrdDocumentos.SelectedRow.Cells = (4). Text (does not work that way) 
                 
             'GrdDocumentos.SelectedIndex = SelectedGridRow.RowIndex 
             'Delete the record 
             'Implement this on your own:) 

          Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim Row As GridViewRow = GrdDocumentos.Rows(Index)
            Dim relIDAs String = Row.Cells(2).Text.Trim

             DeleteRecordByID (relID) 
         End If 
End Sub

ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub DeleteRecordByID (ByVal RegID As Integer)
  2.  
  3. Dim Sql As String
  4. Dim cmd As SqlCommand
  5.  
  6. Dim connection As SqlConnection
  7.  
  8. connection = New SqlConnection (ConfigurationManager.ConnectionStrings ( "Timesheet"). ConnectionString)
  9.  
  10. Sql = "DELETE FROM REL_PROJETOS"
  11. Sql + = "WHERE REL_ID =" & RegID
  12.  
  13. cmd = New SqlCommand (Sql, connection)
  14.  
  15. Try
  16. conexao.Open ()
  17.  
  18. cmd.Connection = connection
  19.  
  20. cmd.CommandType = CommandType.Text
  21.  
  22. cmd.CommandText = Sql
  23.  
  24. cmd.ExecuteNonQuery ()
  25. Catch ex As Exception
  26. lblMensagem.Text = "Error Occurred While Deleting:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString
  27. Finally
  28. conexao.Close ()
  29. GrdDocumentos.DataBind ()
  30. End Try
  31. End Sub Protected Sub GrdDocumentos_SelectedIndexChanging (ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged
  32. RelID = GrdDocumentos.SelectedRow.Cells (12). Text
  33. End Sub
  34.  

Then I need to get the ID to be able to delete the desired record.

Thanks and a hug
please see the bold-red text. Hope I can help you
Reputation Points: 11
Solved Threads: 17
Junior Poster
Kusno is offline Offline
191 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Change panel Size At Runtime
Next Thread in ASP.NET Forum Timeline: ajax toolkit modal popup extender





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC