Solved

Collect datakeys from datalist when looping thorugh rows

Posted on 2008-06-10
2
1,255 Views
Last Modified: 2011-10-03
hi

i have made a datalit that shows a list of items with a text box next to each item. i want to be able to enter a value into each text box and then have the user click one button "Update all" and it to then update all the record that are shown.

each row is one record.

i have started to do this by using the code below to loop thorugh each row and collect the text box.

i also need to collect the datakey whch is defined in the datalist so that i can update the correct record.

i have used this code from a tutorial online but now i am unable to get it to work
Protected Sub SaveAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveAll.Click

        Dim dlitem As DataListItem

        Dim installed As TextBox

        Dim itemID As Integer
 

        For Each dlitem In DataList1.Items

            installed = CType(dlitem.FindControl("Installedtext"), TextBox)

            itemID = Convert.ToInt32(DataList1.DataKeys[Items.itemindex])
 

        Next
 

    End Sub

Open in new window

0
Comment
Question by:bolt81
2 Comments
 
LVL 22

Accepted Solution

by:
prairiedog earned 500 total points
ID: 21754592
This line is not right:
itemID = Convert.ToInt32(DataList1.DataKeys[Items.itemindex])

VB.NET does not support square brackets. Change it to:
itemID = Convert.ToInt32(DataList1.DataKeys(dlitem.ItemIndex))
0
 
LVL 1

Author Closing Comment

by:bolt81
ID: 31465840
thanks i should have seen that
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 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

15 Experts available now in Live!

Get 1:1 Help Now