Finding a control inside an <itemtemplate>

J

Jim in Arizona

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
 
C

clintonG

J

Jim in Arizona

Eliyahu said:
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.
 
J

Jim in Arizona

Jim said:
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/QuickStartv20/aspnet/doc/ctrlref/data/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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top