Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Datalist referencing a textbox with javascript

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Neil Steventon - 25 Oct 2007 11:44 GMT
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
Braulio Diez - 25 Oct 2007 14:04 GMT
I would play with the event OnItemDataBound and the ClientID of the current
button:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.datalist.item
databound.aspx


Good luck
  Braulio

/// ------------------------------
/// Braulio Diez
///
/// http://www.tipsdotnet.com
/// ------------------------------

> Hi All,
>
[quoted text clipped - 8 lines]
>
> Neil
Neil Steventon - 25 Oct 2007 15:21 GMT
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

> I would play with the event OnItemDataBound and the ClientID of the current
> button:
[quoted text clipped - 22 lines]
> >
> > Neil
Teemu Keiski - 25 Oct 2007 17:17 GMT
I've also blogged about it in the past
http://aspadvice.com/blogs/joteke/archive/2005/06/23/2341.aspx

The example itself is a bit bad since you can just use this keyword in that
case, but getting ID with that idea is the point

Signature

Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

>I had a play and managed to work a way to get what I wanted. Thanks for
>point
[quoted text clipped - 61 lines]
>> >
>> > Neil

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.