X
Xiru
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()
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()