DataList

B

brian

This is my first attempt at creating a DataList control.
The DataList contains a Lable that holds a time. I
placed a button in the EditTemplate section and a text
box that if pressed it will update the time for that text
box to current time. I can update the time if I manually
put in the current time.

I need help assigning that button to the text box in the
edit template section. I can't directly reference the
text box and button controls from code behind by name
because it wont recogonize them. Such as 'me.date.text'

Can someone please give me a little advice?
 
J

J. Walker

Here's how I've done it in the past...

In the datalist, go to the HTML editor and find where your <asp:button> tag
is located. Add an onclick event handler to it so it looks like the
following:

<asp:button id="btnSetTime" runat="server" text="Set Time"
onclick="SetTime"></asp:button>

Then, in your code-behind file you'll have a proc such as ..
Protected Sub SetTime(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim btnSetTime As Button = CType(sender, Button)
Dim dlItem As DataListItem = CType(btnSetTime.NamingContainer,
DataListItem)
Dim txtCurrentTime As TextBox =
CType(dlItem.FindControl("txtCurrentTime"), TextBox)

txtCurrentTime.Text = Now.ToShortTimeString
End Sub

Let me know if you need help with this. Took me a long time to finally
figure it out when I was first looking.
 

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

Staff online

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,087
Latest member
JeremyMedl

Latest Threads

Top