Solved

How to delete listview row and update database table at the same time..

Posted on 2010-11-10
4
540 Views
Last Modified: 2012-05-10
Hi,

I have a listview that has this selectcommand:

SelectCommand="SELECT * FROM [XXX] WHERE ([id] = @id) ORDER BY [seqNr] ASC"

I have no problem deleteing a row in my listview:

DeleteCommand="DELETE [XXX] WHERE ([ControlId]=@ControlId)"

I want the seqNr to be updated at the same time as the row is deleted. For example I have a lisview with 10 rows and I delete row 7, then I want to the column seqNr in my table to be updated. I have tried something like this:

Dim iSeq As Integer
                Dim iCtlid As Integer

                Dim i As Integer
                Dim test As String
                test = ListViewFormControls.Items.Count

                For i = 0 To ListViewFormControls.Items.Count - 1
                    iCtlid = ListViewFormControls.DataKeys(i).Value
                    iSeq = i + 1
                    UpdateFieldSequence(iCtlid, iSeq)
                Next

But this fires before the actual delete, so the column seqNr is a mess...

I hope you understand my problem.
0
Comment
Question by:mattegol
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:CmdoProg2
ID: 34104448
Is your code in the ItemDeleted event handler?
0
 

Author Comment

by:mattegol
ID: 34109699
Yes

Protected Sub ListViewFormControls_ItemDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewDeleteEventArgs) Handles ListViewFormControls.ItemDeleting

I have no problem getting it to work one by one, but I can't make it happen at the same time  by clicking the delete button.
0
 
LVL 12

Accepted Solution

by:
CmdoProg2 earned 500 total points
ID: 34120011
I'm confused. You answered that the code is in the deleted event, but are showing the deleting event.  The deleting event occurs before the record is removed, thus renumbering will not work.  The deleted event occurs after the record has been removed.

Try ...

Protected Sub ListViewFormControls_RowDeleted(ByVal sender as Object, ByVal e As System.Web.UI.WebControls.ListViewDeletedEventArgs) Handles ListViewFormControls.ItemDeleted
0
 

Author Closing Comment

by:mattegol
ID: 34121202
Sorry my bad, I mixed it up...

It works like a charm now.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question