How loop datalist to retrieve textbox value?

V

VB Programmer

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?
 
E

Eliyahu Goldin

foreach (DataListItem item in myDataList.Items)
{
myTextBox = item.FindControl ("textboxId");
}

Note, that the textbox in the item template should have runat="server".

Eliyahu
 
V

VB Programmer

I tried looping thru the datalist like this:

For Each i As DataListItem In Me.DataList1.Items
Dim CartId As Label = CType(i.FindControl("Label1"), Label)
Dim Qty As TextBox = CType(i.FindControl("txtQty"), TextBox)
Response.Write(CartId.Text & ":" & Qty.Text & "<br>")
Next

Qty gets filled properly. But, CartId ALWAYS comes up blank even though I
visually can see that there's a .text value. Any ideas why?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top