473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Retrieve DataList Value

I would like to retrieve the value from a DataList on postback. I can
read the ItemIndex and values from a child TextBox but not cannot seem
to find a way to read a databound item on the datalist. Here is some
code to help clarify. I want to display the items from a shopping list
that had a unit number filled in a textbox next to the product:

' Create a holding place for list items with units filled in
Dim itemsUnits As New DataSet
Dim itemUnitsTable As DataTable
Dim itemUnitsRow As DataRow
' Add new table
itemUnitsTable =
itemsUnits.Tables.Add("PurchaseListItems")

' Define Columns
With itemUnitsTable
.Columns.Add("list_item_id", GetType(System.Int16))
.Columns.Add("list_item_name", GetType(System.String))
.Columns.Add("purchase_list_item_units",
GetType(System.Int16))
End With
' Fetch list items
For Each aItem As DataListItem In DataList1.Items
' Find nested datalist control for list items
Dim bList As DataList = aItem.FindControl("DataList2")

' Iterate through list items to create the new dataset
For Each bItem As DataListItem In bList.Items
Dim pTextBox As TextBox =
bItem.FindControl("Textbox1")
Dim productId As Integer = bItem.ItemIndex
' ****** HERE IS WHERE I NEED HELP **********
'Dim productName As String = bItem.DataItem
'Dim productName As String =
DataBinder.Eval(bItem.DataItem, "Product")
' *********************************************

If pTextBox.Text = "" Then pTextBox.Text = 0
Dim productUnits As Integer = CInt(pTextBox.Text)
If productUnits > 0 Then
' Create a new row to store values
itemUnitsRow = itemUnitsTable.NewRow
With itemUnitsRow
.Item("list_item_id") = productId
.Item("list_item_name") = productName
.Item("purchase_list_item_units") =
productUnits
End With
' Now add rows to DataTable
itemUnitsTable.Rows.Add(itemUnitsRow)
End If
Next
Next
' Bind selected list items for confirmation
DataList3.DataSource = itemsUnits
DataList3.DataBind()
Nov 18 '05 #1
0 1430

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark | last post by:
Hi, I have a datalist that contains a textbox as well as a dropdown list. For each single row in the datalist the associated dropdown list can have at least one value What I would like to be...
4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
2
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the...
3
by: webserverpete | last post by:
I am new to ASP.NET in general, but I do have experience with classic ASP. I am using a DataList control with a hidden value to submit to a different page, however I do not know how to get to that...
6
by: Paul | last post by:
I am trying to use a DataList and the ItemTemplate. I am binding the Datalist to a SQL query that gives me a list of Items with a Parent Category. I want to loop through all the items, but...
2
by: VB Programmer | last post by:
I have a datalist for a shopping cart summary. Each data "row" has a text box where they can enter a quantity. How do I loop thru the entire datalist to figure out the total shopping cart price?
1
by: William Oliveri | last post by:
Hi all, I"ve been trying to retrieve the names of each selected items in a Datalist. So I've been trying to loop through each entry in the datalist to retrieve the name of each entry. I...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
1
by: terminul | last post by:
Hi I have a datalist which loops through the categories and within the datalist I have a CheckBoxList which are bound on the DataList's OnItemDataBound. The only problem I have is retrieving...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.