| | |
Take the ID Line GridView popular handbook
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 28
Reputation:
Solved Threads: 0
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:
Then I need to get the ID to be able to delete the desired record.
Thanks and a hug
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)
Protected Sub GrdDocumentos_RowDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdDocumentos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim l As LinkButton = DirectCast (e.Row.FindControl ( "LinkButton1"), LinkButton) l.Attributes.Add ( "onclick", ( "javascript: return" & "confirm ( 'Really delete the Document") & DataBinder.Eval (e.Row.DataItem, "REL_DOCUMENTO") & "?')") End If End Sub
ASP.NET Syntax (Toggle Plain Text)
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:) DeleteRecordByID (relID) End If End Sub
ASP.NET Syntax (Toggle Plain Text)
Private Sub DeleteRecordByID (ByVal RegID As Integer) Dim Sql As String Dim cmd As SqlCommand Dim connection As SqlConnection connection = New SqlConnection (ConfigurationManager.ConnectionStrings ( "Timesheet"). ConnectionString) Sql = "DELETE FROM REL_PROJETOS" Sql + = "WHERE REL_ID =" & RegID cmd = New SqlCommand (Sql, connection) Try conexao.Open () cmd.Connection = connection cmd.CommandType = CommandType.Text cmd.CommandText = Sql cmd.ExecuteNonQuery () Catch ex As Exception lblMensagem.Text = "Error Occurred While Deleting:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString Finally conexao.Close () GrdDocumentos.DataBind () End Try End Sub Protected Sub GrdDocumentos_SelectedIndexChanging (ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged RelID = GrdDocumentos.SelectedRow.Cells (12). Text End Sub
Then I need to get the ID to be able to delete the desired record.
Thanks and a hug
•
•
•
•
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)
Protected Sub GrdDocumentos_RowDataBound (ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GrdDocumentos.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then Dim l As LinkButton = DirectCast (e.Row.FindControl ( "LinkButton1"), LinkButton) l.Attributes.Add ( "onclick", ( "javascript: return" & "confirm ( 'Really delete the Document") & DataBinder.Eval (e.Row.DataItem, "REL_DOCUMENTO") & "?')") End If 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)
Private Sub DeleteRecordByID (ByVal RegID As Integer) Dim Sql As String Dim cmd As SqlCommand Dim connection As SqlConnection connection = New SqlConnection (ConfigurationManager.ConnectionStrings ( "Timesheet"). ConnectionString) Sql = "DELETE FROM REL_PROJETOS" Sql + = "WHERE REL_ID =" & RegID cmd = New SqlCommand (Sql, connection) Try conexao.Open () cmd.Connection = connection cmd.CommandType = CommandType.Text cmd.CommandText = Sql cmd.ExecuteNonQuery () Catch ex As Exception lblMensagem.Text = "Error Occurred While Deleting:" & vbCrLf & ex.Message & vbCrLf '& ex.InnerException.ToString Finally conexao.Close () GrdDocumentos.DataBind () End Try End Sub Protected Sub GrdDocumentos_SelectedIndexChanging (ByVal sender As Object, ByVal e As System.EventArgs) Handles GrdDocumentos.SelectedIndexChanged RelID = GrdDocumentos.SelectedRow.Cells (12). Text End Sub
Then I need to get the ID to be able to delete the desired record.
Thanks and a hug
NEVER NEVER NEVER GIVE UP
![]() |
Similar Threads
- Linux and internet gaming (*nix Software)
- GridView and DataTable (ASP.NET)
- "IBMDADB2" failed, error:E_FAIL(0X80004005) (C#)
- String comparsion (ASP.NET)
- Help with displaying items from a database (ASP.NET)
- About sleep() (PHP)
- C++ Books (C++)
- Volunteering for On-line Advertising Agency (Internet Marketing Job Offers)
- C# .NET Gridview (C#)
Other Threads in the ASP.NET Forum
- Previous Thread: Change panel Size At Runtime
- Next Thread: ajax toolkit modal popup extender
Views: 251 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 ajax alltypeofvideos anathor appliances application asp asp.net beginner box browser button c# cac checkbox commonfunctions complex connection control dataaccesslayer database datagridview datalist deployment development dgv dialog dropdownlist dynamic dynamically edit editing embeddingactivexcontrol feedback fileuploader fill findcontrol flash form formatdecimal formview gridview gudi iis image javascript languages list listbox login microsoft mobile mouse mssql news novell numerical opera panelmasterpagebuttoncontrols parent problem project radio redirect registration relationaldatabases reportemail response.redirect richtextbox rows schoolproject search security select services sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl theft tracking treeview validatedate validation vb.net videos vista visualstudio web webapplications webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers





