Solved

Collect datakeys from datalist when looping thorugh rows

Posted on 2008-06-10
2
1,261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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