Datalist referencing a textbox with javascript

G

Guest

Hi All,

I have a datalist that repeats a list of products and has a textbox called
txtQty which you can change. I would like to put a plus and minus image next
to this textbox that when you click it increments the relevant textbox
accordingly. The problem is obviously that the control txtQty gets named by
the datalist control as it renders it. How can I make sure that clicking the
plus/minus image changes the correct txtQty box.

Thanks in advance

Neil
 
G

Guest

I had a play and managed to work a way to get what I wanted. Thanks for point
in the right direction. In order to do it I had tackled it as follows;

1> Placed a literal control in the datalist itemtemplate.


2.> edited ItemDataBoundEvent as follows

Protected Sub dlstICEModels_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlstICEModels.ItemDataBound

Dim tmpDataListItem As DataListItem
tmpDataListItem = CType(e.Item, DataListItem)

Dim tmpLiteral As Literal
tmpLiteral = CType(e.Item.FindControl("Literal1"), Literal)
tmpLiteral.Text = "<img src='UI/images/p.gif' onclick='javascript:"
& tmpDataListItem.ClientID & "_txtQTY.value = (" & tmpDataListItem.ClientID &
"_txtQTY.value * 1) + 1 ;' />"



End Sub

3.> Was suprised that I managed to get it working :). Key thing to watch
out for is also make sure that you use the correct CASE as javascript is not
as forgiving as VB.net.

Thanks

Neil
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top