468,544 Members | 1,767 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

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 1268

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by V. Jenks | last post: by
2 posts views Thread by Chris Fink | last post: by
6 posts views Thread by Paul | last post: by
2 posts views Thread by VB Programmer | last post: by
1 post views Thread by William Oliveri | last post: by
1 post views Thread by AJ | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.