Datalist referencing a textbox with javascript

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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
 
Back
Top