DataList

  • Thread starter Thread starter brian
  • Start date Start date
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?
 
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.
 
Back
Top