Solved

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

Posted on 2010-11-10
4
533 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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

807 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