Wrox Programmer Forums
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old August 25th, 2011, 09:02 AM
Registered User
Join Date: Jun 2011
Posts: 8
Thanks: 1
Thanked 0 Times in 0 Posts
Default Control used in loop?

Could you please help with this question - I appreciate it greatly .... I have an ado.net connection on my page with a for...each loop that loops through comments posted by users. The id of the comment is obviously different on each loop - I want to place a button in each loop that gives the user (if it is there comment) the option to delete their comment.

How do I get the button control to have the ID as the value for each button and still fire the delete function in the code behind. Basically multiple buttons generated with unique id's on each loop all calling the same event and passing the id to the event.

I've looked everywhere and haven't found any posts that match my situation.

As a work around I can make a text link and direct them to a "delete" page, drop the record, and direct back but I wanted to do this on a post back or in an update panel - much cleaner for the user.

Thanks for any direction on this,

Old August 25th, 2011, 09:12 AM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts

Hi Kenneth,

For questions not directly related to my book, please pick an appropriate forum from this list: http://p2p.wrox.com/asp-net-4-539/ instead. This makes it easier for everyone to find what they are looking for.

That said, here's what I would do:

1. Bind the data to a ListView
2. Set the CommandArgument of the delete button to the ID of the comment
3. Handle the appropriate event
4. Look at the CommandArgument and use that to edit the comment.


Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Click event not firing for Dynamic button control when it has validation control Gayathri79 ASP.NET 3.5 Basics 5 August 20th, 2010 06:58 PM
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
Loop through form looking for Combo Control feets Access VBA 3 November 20th, 2007 09:17 AM
Unique Control IDs inside a loop using a varible Joshua Sebastian Classic ASP Basics 2 February 3rd, 2005 10:44 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.