473,809 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate?

If I have this code for repeater, it gives a compilation error saying
"The type or namespace name 'MyValue2' could not be found":

<asp:Repeater id="MyList" runat="server">
<ItemTemplate >
<%#Container.Da taItem%><br>
<% MyValue2.Text = "ghi"; %>
<asp:TextBox ID="MyValue2" Runat="server"/>
<br>
</ItemTemplate>
</asp:Repeater>

Presumably that's because the MyValue2 control is inside an
ItemTemplate that gets repeated multiple times, so each instance of
MyValue2 gets a unique ID when the page is actually rendered, and the
C# code can't find the "MyValue2" because they were given a series of
unique names instead. (In fact I can even see their IDs in the source
code of the rendered page -- MyList__ctl0_My Value2,
MyList__ctl1_My Value2, etc.)

So, is there a way to have inline code inside the ItemTemplate that
can modify a control that's also repeated inside the template?

I have four ASP.Net books and I can't find any examples in any of them
showing how to do this... Maybe it can't be done?

-Bennett
Nov 18 '05 #1
1 2568
I use the ItemDatBound in my grids to manipulate stuff.
I assume you can do the same for a Repeater.
=============== =============== =============
Sample code:
=============== =============== =============
Private Sub dg1_ItemDataBou nd(ByVal sender As System.Object, ByVal e As
DataGridItemEve ntArgs) Handles dg1.ItemDataBou nd
If e.Item.ItemType = ListItemType.He ader Then
'do something to the header
End If

If e.Item.ItemType = ListItemType.It em OrElse e.Item.ItemType =
ListItemType.Al ternatingItem Then
'need to take paging into account!
Dim mIndex As Integer = CType(sender, DataGrid).PageS ize *
CType(sender, DataGrid).Curre ntPageIndex + e.Item.ItemInde x

'set Status hyperlink
Dim oHylStatus As HyperLink = CType(e.Item.Fi ndControl("hylS tatus"),
HyperLink)
If mCollection(mIn dex).statustext = "None" Then
oHylStatus.Navi gateUrl = ""
Else
oHylStatus.Navi gateUrl = "javascript:..; "
End If
oHylStatus.Text = mCollection(mIn dex).statustext

If mCanAmend=True Then
Dim oBtnAmend As ImageButton = CType(e.Item.Fi ndControl("btnA mend"),
ImageButton)
If mCollection(mIn dex).status = "XYZ" Then
oBtnAmend.Visib le = True
Else
oBtnAmend.Visib le = False
End If
End If

End If
End Sub

--
Joe Fallon


"Bennett Haselton" <be*****@peacef ire.org> wrote in message
news:e6******** *************** ***@posting.goo gle.com...
If I have this code for repeater, it gives a compilation error saying
"The type or namespace name 'MyValue2' could not be found":

<asp:Repeater id="MyList" runat="server">
<ItemTemplate >
<%#Container.Da taItem%><br>
<% MyValue2.Text = "ghi"; %>
<asp:TextBox ID="MyValue2" Runat="server"/>
<br>
</ItemTemplate>
</asp:Repeater>

Presumably that's because the MyValue2 control is inside an
ItemTemplate that gets repeated multiple times, so each instance of
MyValue2 gets a unique ID when the page is actually rendered, and the
C# code can't find the "MyValue2" because they were given a series of
unique names instead. (In fact I can even see their IDs in the source
code of the rendered page -- MyList__ctl0_My Value2,
MyList__ctl1_My Value2, etc.)

So, is there a way to have inline code inside the ItemTemplate that
can modify a control that's also repeated inside the template?

I have four ASP.Net books and I can't find any examples in any of them
showing how to do this... Maybe it can't be done?

-Bennett

Nov 18 '05 #2

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

Similar topics

2
5324
by: theComputer7 | last post by:
I cut down the code to make this half way understandable... I have read Data Grid girls caution about over use of dynamic controls. I truly believe what I am doing requires dynamically inserted user controls. Worse I'm trying to add dynamic user controls from within a repeater loop (looping through attributes)... I bind to a function in the code behind and pass in the attribute. <asp:repeater id="rAttributes" Runat="server">
5
1598
by: Guoqi Zheng | last post by:
Dear sir, If I need to use a function on xxx.aspx page, e.g. on a repeater control, I have to define this function inside xxx.aspx.vb file, if I put it in the module class, it will not work so I have to copy the same function into all aspx page which may need it. Is it possible that I define this function something in the application, I can use it on every .aspx page??
4
34534
by: huzz | last post by:
I am trying to access a DropDownList control inside a repeater using ItemCommand as shown below but for some reason i can't access the DropDownList. When i step through the debug i get <undefine value> for the DropDownList What am i doing wrong? <asp:Repeater ID="Repeater1" Runat="server" OnItemDataBound="create_ddl" OnItemCommand="Repeater1_ItemCommand"> <HeaderTemplate>
2
1392
by: James Moore | last post by:
I've got a datagrid. One of the elements in the grid is a comma-seperated string. I'd like to split the string and create N linkbuttons, one for each element of the string. Creating the grid with the original string isn't a problem, but I'm not sure what the best way is to create the individual linkbuttons. My first thought was to create a method that split the string and stashed the array inside the page object as a public property....
3
2698
by: Thubaiti | last post by:
Hi, I have this code in my ASP.NET and I want to convert it to C# (code behind) <asp:Repeater id="subCategoryRepeater" runat="server"> <ItemTemplate> <ul> <li> <asp:HyperLink id="subCategoryHyperLink" runat="server" NavigateUrl='<%# "subcategory.aspx?subcategoryid=" +
0
10564
by: datakix | last post by:
After 16 hours of frustration, I've managed to solve this problem for a project I'm working on. The 'trick' is set EnableViewState="False" for the asp:textbox inside the Repeater control. The problem is that by default the asp:textbox ViewState is True. This means that the textbox value is automatically preserved between postback (saved in the __VIEWSTATE hidden field and restored during a page postback).
2
1737
by: Nobody | last post by:
I have an aspx page where I have a repeater control that repeats a asp:LinkButton. When I click on one of the links, I get a post back, and the page flashes. A friend told me to look into ATLAS/AJAX, but didn't go into much detail. From what I read/gathered, I came up with this code: <asp:SqlDataSource ID="dsCategories" runat="server" ConnectionString="<%$ ConnectionStrings:cstrDataSource %>" SelectCommand="SELECT , FROM ORDER BY ">...
1
1947
by: Øyvind Isaksen | last post by:
I need to know how to handle controls inside a repeater, how to send and recieve data from another page to one spesific control inside a repeater. Clue: I have a repeater that dynamicly lists out different kind of webcontrols (based on some criterias). Each textboxes inside the repeater need to have a "browse" button, when clicking that button another page shall open (popup) and the user can bwrowse for some content to insert. When...
1
4650
by: Andy B | last post by:
I have a repeater control with an ItemTemplate inside of it. In the ItemTemplate, I have a div with a link that calls a javascript function to make an asp:Panel control visible or invisible. I need to make the ID of the panel equal to this databinding expression: "d<%# DataBinder.Eval(Container, "ItemIndex") %>" Any ideas how to do this? I keep getting errors about the expression is too complex for the ID attribute, it is not a valid...
0
10639
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...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10383
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
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
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
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.