wills

wills

  • NA
  • 2
  • 0

asp.net 2.0 c# FormView

Apr 25 2006 12:54 PM

How can I access the controls I add to the ItemTemplate from the code
behind file? For example, I added a label named LabelMN to the
ItemTemplate 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 context


After that error I tried the following:

string MobileNumber = formview1.FindControl("LabelMN").ToString();
System.Web.UI.WebControls.Label

No error, but not the actual value of the label.

Any ideas?