How can I access the controls I add to the ItemTemplate from the codebehind file? For example, I added a label named LabelMN to theItemTemplate and I want to set its value to a variable in the codebehind.
Design view:<asp:FormView id="formview1" DataSourceID="SqlDataSource1" runat="server" DataKeyNames="EFID" DefaultMode="ReadOnly"> <ItemTemplate> <asp:Label id="LabelMN" runat="server" Text='<%# Bind("ECP")%>' /> </ItemTemplate></asp:FormView>
Code view: string MobileNumber = formview1.Row.FindControl(LabelMN).ToString();
Error:Error 1 The name 'LabelMN' does not exist in the current contextAfter that error I tried the following:string MobileNumber = formview1.FindControl("LabelMN").ToString();System.Web.UI.WebControls.LabelNo error, but not the actual value of the label.Any ideas?