Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 February 18th, 2004, 12:03 PM
Authorized User
 
Join Date: Feb 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default Updating & Deleting Rows from a Repeater

Hi. I'm not sure if this can be done as I cannot find any examples in the books...

I have a Web form that is populated with a Repeater by using a SQL statement. I am pulling data from more than one table, so I cannot use the Dataset commands for accessing rows. My form allows the user to modify data in textboxes & then press either 'Update' to send an update command for that row or 'Delete' to delete the row altogether.

How do I access the data that I have passed to the Repeater in order to build the necessary SQL statements? I have passed the primary key for the entity that is being edited in a hidden field. I could use that value to build the SQL statement, which would be activated when the onClick event is processed. But I have not been able to access that value. Or may I simply refernce an index for each row? This has me completely stumped at the moment. Any ideas?

Thanks.



 
Old February 18th, 2004, 01:44 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What do you mean by "I have passed the primary key for the entity that is being edited in a hidden field."? Do you mean you have a hidden form field? This is not the correct way to do this. And unless you can correctly map a row index to a table row ID (which is highly unlikely not to mention terribly fragile) you can't use the row idea.

You should consider using the DataList control. The DataList class has a property called "DataKeyField". You can specify your table's key field there and the web control will maintain a list of key values that correspond with each row. So you can then grab that when you process a row event:

Private Sub myDataList_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs ) Handles myDataList.ItemCommand
    Dim nRowID As Integer
    nRowID = CType(myDataList.DataKeys.Item(e.Item.ItemIndex), Integer)
End Sub

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 18th, 2004, 03:06 PM
Authorized User
 
Join Date: Feb 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter -

What I meant was that I have passed the three primary field ID's are returned by the SQL SELECT statement and placed along with the data that the user will be editing into the Repeater object. Because my SQL SELECT statement is pulling information from multiple tables, and the data is presented in textboxes, not simple tabular format, I need to use the Repeater to format a template.

Can I use the DataList with a Repeater? I read in the .NET Framework Call Library that the Repeater has an ItemCommand Event. Could I use that?

Let me know if I need to explain more what I am trying to do.

Thanks.

 
Old February 18th, 2004, 05:08 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The Repeater control is a very simplified Data listing control. The DataList provides the flexibility of row templates like the repeater but also includes some more options that are tailored more for interacting with the data such as the ItemCommand event, and some predefined events (Edit, Update, Cancel, Select). Unforunately, if you need to hold more than one key for your row, you will have to find some work around for it.

Unless you need to interact with the data in the control, versus just being able to see it, you don't need to worry about the ItemCommand event.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old February 19th, 2004, 04:35 PM
Authorized User
 
Join Date: Feb 2004
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Peter -

I moved the SQL commands for inserting, deleting and updating to stored procedures & all is working just fine. No need to find a workaround.

Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Speed up macro - deleting rows icabo Excel VBA 1 October 8th, 2007 02:18 PM
Deleting rows in Winforms Datagrid livehed General .NET 0 May 4th, 2006 01:23 AM
Updating/Deleting from SQL using ASP Tee88 Classic ASP Databases 4 May 6th, 2005 11:14 AM
updating and deleting record PinkyCat Classic ASP Databases 4 March 16th, 2005 05:50 AM





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