0

I have something like this

    <asp:ListView ID="lvOptions" runat="server"">
        <LayoutTemplate>
            <p>Select an option<span>*</span></p>
            <div class="row">
                <asp:Literal runat="server" ID="groupPlaceHolder"></asp:Literal>
            </div>
            <div class="row">
                <div class="w100">
                    <label>
                        Other types:</label>
                    <asp:DropDownList ID="ddlOtherTypes" runat="server" DataTextField="Description" DataValueField="Id"
                        AutoPostBack="true" Enabled="false"
                    </asp:DropDownList>
                </div>
            </div>
        </LayoutTemplate>
        <GroupTemplate>
            <asp:Literal runat="server" ID="itemPlaceHolder"></asp:Literal>
        </GroupTemplate>
        <ItemTemplate>
            <span class="wrap-w50">
                <asp:RadioButton runat="server" ID="rdbOption" AutoPostBack="true" />
                <label>
                    <%# Eval("Description") %></label>
            </span>
        </ItemTemplate>
    </asp:ListView>

And I got here two labels, one fot the Other types DropDownList, and another for each RadioButton. For this labels, I need to add a "for" attribute, and I need the clientID but, if I try to write the attibute like:

for="<%= ddlOtherTypes.ClientID %>"
for="<%= rdbOption.ClientID %>"

I got the error: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). Any suggestions please?

Thank you in advance.

CM.
  • 1
  • 3
  • This may help you: https://forums.asp.net/t/1139381.aspx?what+are+these+special+tags+and+, just remember you are working in `data binding`, you need another `tag` to retrieve the client ID – Prisoner Jan 23 '17 at 09:13
  • Thank you Alex for the comment, I've tried to use <%# tag, but I got the for attibute empty, like: – CM. Jan 23 '17 at 09:25
  • how about this: http://stackoverflow.com/questions/7496348/get-clientid-of-a-control-placed-inside-a-datacontrol – Prisoner Jan 23 '17 at 09:29
  • I would suggest this reading this: http://stackoverflow.com/a/3489526/4045532 – Corporalis Jan 23 '17 at 09:30
  • I can't use an asp:label, because ASP renders a span tag wrapping the label. – CM. Jan 23 '17 at 09:33
  • If you use `AssociatedControlId` on a `asp:label` it will render it as a label element – Corporalis Jan 23 '17 at 09:46

0 Answers0