473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 DataListCommandEventArgs)

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

End Sub

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

Sub AnotherProcedure()
End Sub
TIA,
Jim
Jan 4 '07 #1
5 12874
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*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.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 DataListCommandEventArgs)

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

End Sub

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

Sub AnotherProcedure()
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*******@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP03.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 DataListCommandEventArgs)

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

End Sub

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

Sub AnotherProcedure()
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 DataListCommandEventArgs)

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

End Sub

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

Sub AnotherProcedure()
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 HideOrShowButton()

Dim i As Integer
Dim lblDate As New Label
Dim btnUpdate As New Button
For i = 0 To dlNotes.Items.Count - 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.Visible = True
Else
btnUpdate.Visible = 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*******@hotmail.comwrote in message
news:uP**************@TK2MSFTNGP06.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 DataListCommandEventArgs)

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

End Sub

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

Sub AnotherProcedure()
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 HideOrShowButton()

Dim i As Integer
Dim lblDate As New Label
Dim btnUpdate As New Button
For i = 0 To dlNotes.Items.Count - 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.Visible = True
Else
btnUpdate.Visible = 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
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 =...
0
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...
3
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...
1
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...
1
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=<%#...
2
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
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">...
3
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.