Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now