473,765 Members | 2,097 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Finding a control inside an <itemtemplate >

How do I find a control within a datalist itemtemplate from a sub
procedure that isn't a normal called procedure from a datalist (like the
update, edit, or cancel procedures)?

For instance, normally you find a control and access it's properties and
methods, like so:

Sub Update(ByVal sender As Object, ByVal e As DataListCommand EventArgs)

Dim txtPosted As New TextBox
txtPosted = e.Item.FindCont rol("txtPosted" )

End Sub

How could I do this using a different procedure, like:

Sub AnotherProcedur e()
End Sub
TIA,
Jim
Jan 4 '07 #1
5 12903
The DataList exposes Items collection. navigate to the required item and do
the same FindControl.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Jim in Arizona" <ti*******@hotm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
How do I find a control within a datalist itemtemplate from a sub
procedure that isn't a normal called procedure from a datalist (like the
update, edit, or cancel procedures)?

For instance, normally you find a control and access it's properties and
methods, like so:

Sub Update(ByVal sender As Object, ByVal e As DataListCommand EventArgs)

Dim txtPosted As New TextBox
txtPosted = e.Item.FindCont rol("txtPosted" )

End Sub

How could I do this using a different procedure, like:

Sub AnotherProcedur e()
End Sub
TIA,
Jim

Jan 4 '07 #2
Enable trace in the page. Load the page and read the trace to identify the
control in the control tree hierarchy. We have to use the FindControl method
on each object in that hierachy for those instances when objects are deeply
nested into templates. Don't forget to cast the found object to the proper
type.
<%= Clinton Gallagher
NET csgallagher AT metromilwaukee. com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-...8&z=17&l=0&m=h
"Jim in Arizona" <ti*******@hotm ail.comwrote in message
news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
How do I find a control within a datalist itemtemplate from a sub
procedure that isn't a normal called procedure from a datalist (like the
update, edit, or cancel procedures)?

For instance, normally you find a control and access it's properties and
methods, like so:

Sub Update(ByVal sender As Object, ByVal e As DataListCommand EventArgs)

Dim txtPosted As New TextBox
txtPosted = e.Item.FindCont rol("txtPosted" )

End Sub

How could I do this using a different procedure, like:

Sub AnotherProcedur e()
End Sub
TIA,
Jim

Jan 4 '07 #3
Eliyahu Goldin wrote:
The DataList exposes Items collection. navigate to the required item and do
the same FindControl.
Could you please provide an example? I've looked around the net and
can't seem to find one anywhere.

I still consider myself a newbie when it comes to this stuff and am just
now starting to harness the power of the datalist control.

Jan 4 '07 #4
Jim in Arizona wrote:
How do I find a control within a datalist itemtemplate from a sub
procedure that isn't a normal called procedure from a datalist (like the
update, edit, or cancel procedures)?

For instance, normally you find a control and access it's properties and
methods, like so:

Sub Update(ByVal sender As Object, ByVal e As DataListCommand EventArgs)

Dim txtPosted As New TextBox
txtPosted = e.Item.FindCont rol("txtPosted" )

End Sub

How could I do this using a different procedure, like:

Sub AnotherProcedur e()
End Sub
TIA,
Jim
After some experimentation and trying to follow examples at this location:
http://quickstarts.asp.net/QuickStar.../datalist.aspx

I have come up this this code:

Sub HideOrShowButto n()

Dim i As Integer
Dim lblDate As New Label
Dim btnUpdate As New Button
For i = 0 To dlNotes.Items.C ount - 1

lblDate = dlNotes.Items(i ).FindControl(" lblDate")
btnUpdate = dlNotes.Items(i ).FindControl(" btnUpdate")

If lblDate.Text = "1/4/2007 10:15:00 AM" Then
btnUpdate.Visib le = True
Else
btnUpdate.Visib le = False
End If
Next

End Sub

This is unrefined, but is a good start to what I'm hoping for. My goal
is to make visible or invisible a button based on the original post time
of the db record.

If anyone can think of a better way of doing this that's not overly
complicated, please post!

Thanks to those who replied.
Jan 4 '07 #5
This code is absolutely fine.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Jim in Arizona" <ti*******@hotm ail.comwrote in message
news:uP******** ******@TK2MSFTN GP06.phx.gbl...
Jim in Arizona wrote:
How do I find a control within a datalist itemtemplate from a sub
procedure that isn't a normal called procedure from a datalist (like the
update, edit, or cancel procedures)?

For instance, normally you find a control and access it's properties and
methods, like so:

Sub Update(ByVal sender As Object, ByVal e As DataListCommand EventArgs)

Dim txtPosted As New TextBox
txtPosted = e.Item.FindCont rol("txtPosted" )

End Sub

How could I do this using a different procedure, like:

Sub AnotherProcedur e()
End Sub
TIA,
Jim

After some experimentation and trying to follow examples at this location:
http://quickstarts.asp.net/QuickStar.../datalist.aspx
>
I have come up this this code:

Sub HideOrShowButto n()

Dim i As Integer
Dim lblDate As New Label
Dim btnUpdate As New Button
For i = 0 To dlNotes.Items.C ount - 1

lblDate = dlNotes.Items(i ).FindControl(" lblDate")
btnUpdate = dlNotes.Items(i ).FindControl(" btnUpdate")

If lblDate.Text = "1/4/2007 10:15:00 AM" Then
btnUpdate.Visib le = True
Else
btnUpdate.Visib le = False
End If
Next

End Sub

This is unrefined, but is a good start to what I'm hoping for. My goal
is to make visible or invisible a button based on the original post time
of the db record.

If anyone can think of a better way of doing this that's not overly
complicated, please post!

Thanks to those who replied.

Jan 4 '07 #6

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

Similar topics

5
8786
by: tascien | last post by:
I am just wondering... can footertemplate hold data? b/c i want to show the sum of my Invoice in footer template. How can i do that? I could add the sum to the dataset like this: SumColumn = new DataColumn("SumColumn",Double,"Sum(ItemTotal)") ds.tables(0).columns.Add(SumColumn) if i do:
0
1701
by: Andla Rand | last post by:
Hi, I would like to use this feature but in the codebehind. I'm reading from an example text and everything is not codebehind. I would appreciate if you could help me on this. <form runat=server> <asp:DataList id="MyDataList" runat="server" BorderColor="black"
3
2055
by: Ben Becker | last post by:
I am trying to build a custom crosstab type of grid where I take some items in a data grid and based on the content of the current item compared to the previous item, determine if a new row in a table should be created or not. In order to do this, I need to have full control over the conditional logic for how items get displayed within a repeater element which I'm not seeing as possible. How can I cursor through a data set, apply...
1
7645
by: CJM | last post by:
I've copied (& modified) some code from MSDN which uses a Repeater control, but I'm getting an error: Unexpected end of file looking for </HeaderTemplate> As far as I can see I've not made an dramatic changes, and if the MSDN code would work, I would also expect mine to work. As far as the </HeaderTemplate> tag is concerned, I removed it and replaced it - but it did not appear in the Intellisense list.
1
4544
by: Jesper Pedersen | last post by:
Hi ! How do I access the following spillerID and Session from another *aspx page in my application? <ItemTemplate> <a href="player_details.aspx?spillerID=<%# DataBinder.Eval(Container.DataItem, "PlayerID") %>" target="_parent"> <%# DataBinder.Eval(Container.DataItem, "playerFirstName") %> <%#
2
3895
by: Olivier Verdin | last post by:
Hi, It seems that it is not possible to use <il> tag inside an asp.net repeater. Is there any way to overcome this difficulty? Thanks, Olivier
3
2779
by: webserverpete | last post by:
I would like to have multiple <td> in a repeater control. The below code does not work: <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" DataMember="DefaultView"> <HeaderTemplate> <table> </HeaderTemplate> <tr> <ItemTemplate> <td>
3
2947
by: Opa | last post by:
Hi, I have and XMLDataSource which I am using in a GridView control and am customizing the grid with <ItemTemplate>. My XML datasource has an element with an attribute called "private". I want to check the value of the private attribute and if is is true, I DON'T want to display this row of data. I am having trouble with the XPath expression. How is this done? Here is a sample XML source
2
12668
by: deathtospam | last post by:
Is it possible to Databind to a strongly-typed list of integers (List<int>) ? I want to use <%# Databinder.Eval(Container.DataItem, "XXX") %inside a Repeater control in my ASPX page, but I don't know how to get at the List<intvalue. -= Tek Boy =-
0
9568
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
9398
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
10156
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
8831
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
7375
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
5275
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...
0
5419
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
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.