Hi all. I am trying to access a webcontrol (a Textbox) from the EditItemTemplate of a DataList, so I can change it. When I try to do DataList.FindControl("TextboxID") it comes back with null because it doesn't recognize the textbox has rendered. I've tried looking in the DataBinding, DataBound events and those don't work either.
To be more specific, I need to change the value of a textbox when the user uses a Calendar control, so I need to access the control from EditItemTemplate in the Calendar_SelectionChanged event.
Anyone have any ideas or workarounds? Thanks!
Code:
protected void calendar1_SelectionChanged(object sender, EventArgs e)
{
// Access EditItemTemplate Control
}
<asp:DataList ID="DataListMaintenance" runat="server"
oncancelcommand="DataListMaintenance_CancelCommand"
oneditcommand="DataListMaintenance_EditCommand"
onupdatecommand="DataListMaintenance_UpdateCommand"
DataSourceID = "LMMaintDataSource"
ondeletecommand="DataListMaintenance_DeleteCommand">
<EditItemTemplate>
<table width = "100%" cellpadding = "2" cellspacing = "1">
<tr>
<td valign = "top">
<b>Contract Start Date:</b>
</td>
<td>
<asp:TextBox ID="txtContractStart" runat="server" Text = '<%# Bind("ContractStartDate") %>'></asp:TextBox>
<% if (!calDateEdit.Visible)
{ %>
<asp:LinkButton ID="linkChoose" runat="server" onclick="linkChoose2_Click">Choose</asp:LinkButton>
<%} %>
<% if (calDateEdit.Visible)
{ %>
<asp:LinkButton ID="linkCancel" runat="server" onclick="linkCancel2_Click">Cancel</asp:LinkButton>
<%} %>
</td>
<td>
<asp:Calendar ID="calDateEdit" runat="server" Visible ="false"
onselectionchanged="calendar1_SelectionChanged">
<SelectedDayStyle BorderColor="Blue" BorderStyle="Solid" />
</asp:Calendar>
</td>
</tr>
<tr>
<td>
<asp:Button ID="cmdUpdate" runat="server" Text="Update" CommandName = "Update" /> <asp:Button ID="cmdCancel" runat="server" Text="Cancel" CommandName = "Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>
<ItemTemplate>
<table width = "100%" cellpadding = "2" cellspacing = "1">
<tr>
<td valign = "top">
<b>Contract Start Date:</b>
</td>
<td>
<asp:Label ID="lblStart" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "ContractStartDate")%>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>