Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...it was ingeniously designed and all those clicks were for my own good... and that was even before I got my speedy and useful answer to my tekkie question that I eventually posted..."

Geography

Where in the world do Tek-Tips members come from?

asp.net 4.0 gridview delete a record, trouble with data type conversions

DougP (MIS)
24 Jul 12 10:48
trying to get the row Id and then the REcord ID to delete a record form the gridview. I am trying to pass the Row Id to a variable the trying to get eth value of the Record ID out of a cell called "ID"

CODE

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

        Dim RetVal As String

        RetVal = MsgBox("Are you sure you want to delete record?", vbInformation + vbYesNoCancel, "Confirm Delete Record")

        If RetVal = vbYes Then
            Dim RowID As Object = GridView2.Rows(e.RowIndex)
            Session("EditSQLRecordID") = GridView2.Rows(RowID).FindControl("ID")

            'delete record calling the function which calls the stored procedure
            sp_SOWDeleteOneTimeReportingRecord(Session("EditSQLRecordID"))

            Me.GridView2.DataBind()
        End If
    End Sub 

DougP

jbenson001 (Programmer)
24 Jul 12 12:49
Set the DataKeys property on your gridview to whatever column is your ID.
Then in your RowDeleting event do something like this:

CODE

Dim RowID as string =  e.Keys("YourDataKeyNameGoesHere") 

Also, as a side note, do not use a MsgBox. This will only work locally, because your dev machine is the server. Once you roll that code to production, or a staging site, it will run, but you will never see the popup.
DougP (MIS)
24 Jul 12 13:53
Ok whats is "YourDataKeyNameGoesHere" I tried "ID" but returns "Nothing". I am populating the grid from scratch it's unbound but the column name is ID. it has the Unique Record ID and
if I could just get it I would be a happy camper. no idea why this is so clumsy in .NET? one methosd you can use something and the other method you can't.
I know about message box but can't make anything work with that either. you got a snippet for me to pop up a message?

I know enough .NET to just get by. been doing VB6 and VBA which is much more forgiving than .NET.

DougP

DougP (MIS)
24 Jul 12 14:09
Ok I got it
I was looking on MSDN at datakeyname and added the RED line and it
WORKS !!!!!!!! omg its works after 5 hours of head banging ####

<asp:GridView ID="GridView2" runat="server" BackColor="#CCCCCC" AllowSorting="True"
OnRowDeleting="GridView2_RowDeleting"
DataKeyNames="ID"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4"
CellSpacing="2" ForeColor="Black">
....

DougP

DougP (MIS)
24 Jul 12 14:27
BTW this is the URL where I found the datakeynames
http://msdn.microsoft.com/en-us/library/system.web...

DougP

jbenson001 (Programmer)
24 Jul 12 14:43
Glad you got it. Sorry my explanation wasn't clear enough about setting the DatakeyName property.
As for a pop up, you need to do it on the client side with javascript.
You can use alert('you message');
OR
If you want a return back, you can use confirm:
confirm('are you sure you want to delete this row?');

That will return true or false.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close