| | |
Take the ID Line GridView popular handbook
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
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
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos application asp asp.net bc30451 bottomasp.net browser button c# c#gridviewcolumn checkbox child click commonfunctions compatible confirmationcodegeneration content courier css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock development dgv dropdownlist dynamically edit expose fill flash form formatdecimal forms formview gridview homeedition hosting iframe iis javascript jquery listbox login microsoft mono mouse mssql multistepregistration news numerical objects opera panelmasterpagebuttoncontrols parent radio ratings registration reportemail rotatepage save schoolproject search security serializesmo.table silverlight smartcard smoobjects software sql-server sqlserver2005 suse textbox tracking typeof unauthorized validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webprogramming webservice xml xsl youareanotmemberofthedebuggerusers





