error: can't find control 'mylabel'

Discussion in 'ASP .Net Web Controls' started by Ben, Aug 18, 2006.

  1. Ben

    Ben Guest

    Hi,

    In the code-behind, i can refer to the dropdownlist defined in the aspx file
    with this (e.g.)
    dropdownlist1.sekectedvalue = ...

    but why can i not refer to the label defined in the TemplateField in the
    same aspx file like below?
    This gives the error: "can't find control 'mylabel' ":
    mylabel.text="ok"

    <asp:TemplateField>
    <ItemTemplate>
    <asp:Label ID="mylabel" Runat="server"
    Text='<%# Bind("field1") %>'></asp:Label>
    </ItemTemplate>
    </asp:TemplateField>

    <asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
    </asp:DropDownList>

    Thanks
    Ben
     
    Ben, Aug 18, 2006
    #1
    1. Advertising

  2. Because it is just a template. If there are 20 rows, there will be 20
    labels. If there are 50 rows, there will be 50 labels.
    So which one could 'myLabel' possibly refer to? How would the page know
    which one of the unknown number of labels that will be created youw ant?

    It can't.

    "Ben" <> wrote in message
    news:...
    > Hi,
    >
    > In the code-behind, i can refer to the dropdownlist defined in the aspx
    > file with this (e.g.)
    > dropdownlist1.sekectedvalue = ...
    >
    > but why can i not refer to the label defined in the TemplateField in the
    > same aspx file like below?
    > This gives the error: "can't find control 'mylabel' ":
    > mylabel.text="ok"
    >
    > <asp:TemplateField>
    > <ItemTemplate>
    > <asp:Label ID="mylabel" Runat="server"
    > Text='<%# Bind("field1") %>'></asp:Label>
    > </ItemTemplate>
    > </asp:TemplateField>
    >
    > <asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
    > </asp:DropDownList>
    >
    > Thanks
    > Ben
    >
     
    Marina Levit [MVP], Aug 18, 2006
    #2
    1. Advertising

  3. Ben

    Ben Guest

    Thanks for replying.
    This is bad news for me, because i defined an InsertItemTemplate containing
    a dropdownlist with the possible values into the detailsview (put into
    insert mode) .
    Result: the Controlparameter can't find controlID="dropdownlist1".
    How can i put the selectedvalue of the dropdownlist into that template field
    for inserting the new record?

    Thanks again
    Ben

    See part of code:

    <asp:SqlDataSource ID="SqlDataSource1"
    ...
    InsertCommand="INSERT INTO [pc] ([name], [place]) VALUES (?, ?, @pl)"
    "OldValuesParameterFormatString="original_{0}"
    ProviderName="System.Data.OleDb">
    <InsertParameters>
    <asp:parameter Name="name" Type="String" />
    <asp:ControlParameter ControlID="dropdownlist1" Name="pl"
    PropertyName="SelectedValue" Type="String" />
    </InsertParameters>
    </asp:SqlDataSource>

    <asp:DetailsView ID="DetailsView1" runat="server" DataKeyNames="pcnr"
    DataSourceID="SqlDataSource1" DefaultMode="Insert">
    <Fields>
    <asp:BoundField DataField="pcnr" HeaderText="pcnr"
    ReadOnly="True"
    <asp:BoundField DataField="name" />
    <asp:TemplateField >
    <InsertItemTemplate>
    <asp:DropDownList ID="DropDownList1"
    runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
    DataTextField="place DataValueField="placel">
    </asp:DropDownList>
    </InsertItemTemplate>
    </asp:TemplateField>
    <asp:CommandField ShowInsertButton="True" />
    </Fields>
    </asp:DetailsView>

    asp:SqlDataSource ID="SqlDataSource2"
    ....


    "Marina Levit [MVP]" <> schreef in bericht
    news:%...
    > Because it is just a template. If there are 20 rows, there will be 20
    > labels. If there are 50 rows, there will be 50 labels.
    > So which one could 'myLabel' possibly refer to? How would the page know
    > which one of the unknown number of labels that will be created youw ant?
    >
    > It can't.
    >
    > "Ben" <> wrote in message
    > news:...
    >> Hi,
    >>
    >> In the code-behind, i can refer to the dropdownlist defined in the aspx
    >> file with this (e.g.)
    >> dropdownlist1.sekectedvalue = ...
    >>
    >> but why can i not refer to the label defined in the TemplateField in the
    >> same aspx file like below?
    >> This gives the error: "can't find control 'mylabel' ":
    >> mylabel.text="ok"
    >>
    >> <asp:TemplateField>
    >> <ItemTemplate>
    >> <asp:Label ID="mylabel" Runat="server"
    >> Text='<%# Bind("field1") %>'></asp:Label>
    >> </ItemTemplate>
    >> </asp:TemplateField>
    >>
    >> <asp:DropDownList ID="dropdownlist1" runat="server" AutoPostBack="True" >
    >> </asp:DropDownList>
    >>
    >> Thanks
    >> Ben
    >>

    >
    >
     
    Ben, Aug 18, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ad
    Replies:
    2
    Views:
    889
  2. Ben
    Replies:
    2
    Views:
    421
  3. Wybo Dekker
    Replies:
    1
    Views:
    395
    Yukihiro Matsumoto
    Nov 15, 2005
  4. vdvorkin
    Replies:
    0
    Views:
    437
    vdvorkin
    Feb 10, 2011
  5. vdvorkin
    Replies:
    3
    Views:
    863
    vdvorkin
    Feb 14, 2011
Loading...

Share This Page