Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 18th, 2004, 12:03 PM
Authorized User
 
Join Date: Feb 2004
Location: Philadelphia, , USA.
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.



  #2 (permalink)  
Old February 18th, 2004, 01:44 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
  #3 (permalink)  
Old February 18th, 2004, 03:06 PM
Authorized User
 
Join Date: Feb 2004
Location: Philadelphia, , USA.
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.

  #4 (permalink)  
Old February 18th, 2004, 05:08 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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.
  #5 (permalink)  
Old February 19th, 2004, 04:35 PM
Authorized User
 
Join Date: Feb 2004
Location: Philadelphia, , USA.
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.

 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:41 PM.


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