473,804 Members | 3,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Referring to a textbox within an ItemTemplate

With HTML, how do I get the value of a textbox in an ItemTemplate column
within a datagrid?

Simple shopping cart. For each row: 1 column is a textbox where they can
enter the quantity. 1 column is an update button that calls UpdateCart.aspx
passing it the CartId and Qty.

Here's the HTML....

<asp:TemplateCo lumn>
:
<ItemTemplate >
<asp:TextBox id=txtQty runat="server" Width="28px" Text='<%#
DataBinder.Eval (Container.Data Item, "ProductQty ") %>'>
</asp:TextBox>
</ItemTemplate>
:
<ItemTemplate >
<A href='UpdateCar t.aspx?CartId=< %#
DataBinder.Eval (Container.Data Item, "CartID") %>&amp;Qty=<%# txtQty.text
%>'>
<asp:Image id="Image3" runat="server"
ImageUrl="Resou rces/UpdateBtn.jpg"> </asp:Image></A>
</ItemTemplate>
</asp:TemplateCol umn>

It doesn't like txtQty.text. I also tried entering
DataBinder.Eval (Container.Data Item, "ProductQty ") but, of course, it selects
the ORIGINAL value...

Sorry. I'm just confused.

Thanks!
Nov 20 '05 #1
1 7877
You are confusing server-side with client-side code. When you are
assigning the querystring value of <%#txtQty.text% >, you are hard-coding
the value to whatever the server-side last knew about.

Normally, it would be as simple as using a bit of javascript to set the
value, as in:

<a href="#" onclick="window .location='Upda teCart.aspx?Car tId=<%#
DataBinder.Eval (Container.Data Item, "CartID") %>&amp;Qty=' +
document.getEle mentById['txtQty'].value">

However, you're in a datagrid (pretty sure since you're using
TemplateColumns ), so the txtQty ID is going to change for every row. So
we can't hard-code this form ID value in the link. That means we will
have to evaluate it per row and generate the URL for the link per row.

You will need to make the link runat=server and give it an ID like
lnkUpdate.

You will need an event handler for the ItemDataBound event and you will
need to to update the link's address in it. Like this:

private sub UpdateLink(s as object, e as datagriditemeve ntargs) handles
dgWhatever.Item DataBound
dim txtQty as textbox
dim lnkupdate as htmlAnchor
dim js as string
if e.item.itemtype =item or e.item.itemtype =alternatingite m then
lnkupdate=e.ite m.findcontrol(" lnkUpdate")
txtqty=e.item.f indcontrol("txt Qty")
js="window.loca tion='UpdateCar t.aspx?CartId=" & e.item.dataitem
("CartID") & "&Qty=' + document.getEle mentById['" & txtQty.clientid &
"'].value
lnkupdate.attri butes.add("oncl ick",js)
end if
end sub

So what is happening in there is when we are in an item or alternating
item, find the qty text box and the update link. Make a javascript
statement and use the current dataitem's CartID value (which is the same
as you did in the ASPX code), and get the clientID value of the textbox
because it's going to be different for each row.

This code is just off the top of my head so it may not be copy-pasteable,
but the concept is correct.

Hope this helps.
"VB Programmer" <do**@emailme.c om> wrote in
news:eR******** ******@tk2msftn gp13.phx.gbl:
With HTML, how do I get the value of a textbox in an ItemTemplate
column within a datagrid?

Simple shopping cart. For each row: 1 column is a textbox where they
can enter the quantity. 1 column is an update button that calls
UpdateCart.aspx passing it the CartId and Qty.

Here's the HTML....

<asp:TemplateCo lumn>
:
<ItemTemplate >
<asp:TextBox id=txtQty runat="server" Width="28px" Text='<%#
DataBinder.Eval (Container.Data Item, "ProductQty ") %>'>
</asp:TextBox>
</ItemTemplate>
:
<ItemTemplate >
<A href='UpdateCar t.aspx?CartId=< %#
DataBinder.Eval (Container.Data Item, "CartID") %>&amp;Qty=<%#
txtQty.text %>'>
<asp:Image id="Image3" runat="server"
ImageUrl="Resou rces/UpdateBtn.jpg"> </asp:Image></A>
</ItemTemplate>
</asp:TemplateCol umn>

It doesn't like txtQty.text. I also tried entering
DataBinder.Eval (Container.Data Item, "ProductQty ") but, of course, it
selects the ORIGINAL value...

Sorry. I'm just confused.

Thanks!


Nov 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2232
by: Tyson | last post by:
Hi Very novice sorry. Trying to add a simple query to a textbox...I am getting Enter Parameter Value I have a Form called (frm_tbl_RR_Datacapture). With a series of Textboxes. I am wanting to look at a textbox in the form called(RR_Adjusted_GB_Piece_Size_Input)and lookup the corresponding
0
992
by: KatB | last post by:
Hi, I have a web control (ucTickets) in an asp.net page (MasterPage). From ucTickets, I open a calendar popup window to which I pass a control.value (which textbox to fill with the date). I've always used a change event in the calendar aspx as follows: Protected Sub Change_Date(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim strScript As String = "<script>window.opener.document.Form(0)." +
1
2067
by: clickon | last post by:
For testing purposes i have got a 2 step WizardControl. Eqach step contains a text box, TextBox1 and TextBox2 respectively. If i put the following code in the respective activate event handlers for the two steps, TextBox1.Text ="foo"; and TextBox2.Text = "bar";
1
1580
by: rockdale | last post by:
Hi, All I have an datagrid with alternating color, I also want the back-color of my textbox in ItemTemplate also appears alternating, how could I do that? <asp:datagrid id="dgridEmpHours" width="100%" runat="server" DataKeyField="employee_key" AutoGenerateColumns="False" BorderWidth="0" CellPadding="2" cellSpacing="1" GridLines="None" ShowFooter="True"> <AlternatingItemStyle CssClass="AltBoldtext" />
6
3374
by: rn5a | last post by:
When the EditCommandColumn in a DataGrid is clicked, all the BoundColumns get replaced by TextBoxes so that users can alter the data. By default, the Text in the TextBoxes are left-aligned. Is there any way by which the Text in some of the TextBoxes, not all, be center-aligned or right-aligned? Please note that I am referring to the alignment of the Text in the TextBoxes & NOT the alignment of the TextBoxes within the cells in the...
2
2658
by: AC [MVP MOSS] | last post by:
I have a repeater with a header, footer, and item template. The item template is the only one with server controls (hyperlinks, labels, and a nested repeater). Within the top repeater, I'm handling the ItemDataBound method in the code behind. In this handler, I need to get access to the controls within the ItemTemplate.... however I've only found one way to do this (and i"m not sure why it works). Once I cast the sender (first param...
3
1688
by: =?Utf-8?B?QW5kcmV3IEhheWVz?= | last post by:
Does anyone else find that when they use a table to handle the layout for a FormView template, and they have textboxes set to width="100%", that the rendered input is wider than the cell they are in, even when they are empty?
3
1470
by: Steph | last post by:
hello, l ve tried to list control into a the itemtemplate (datalist). The script run into Page_Init (or Page_Load) and build a ArrayList with the found control ID. if somoene have a solution...
2
5078
by: slao | last post by:
I am unable to get the updated value of textbox within a listview when "Update" link button is clicked which calls a function. <asp:ListView ID="_lvCartItems" OnItemUpdating="CartPartItem_OnItemUpdating" OnItemDeleting="CartPartItem_OnItemDeleting" runat="server"> <LayoutTemplate> <table width="900px" border="0" style="font-size: small"> <tr style="background: #DDDDDD;"> ...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9587
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3827
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.