Solved

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

Posted on 2010-11-10
4
528 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

803 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