开发者

How to allow html control inside a listitem?

The following compile error occurs:

Parser Error Message: The 'Text' property of 'asp:ListItem' does not allow child objects.

Source Error:

Line 468: </asp:ListItem>
Line 469: <asp:ListItem Value="3">
Line 470: Search only continuing stories with at least&nbsp; <input runat="server" id="episodetb" Value="0" style="width:50px" />
Line 471: episodes
Line 472: </asp:ListItem>

When my original code is like this:

< asp:RadioButtonList ID="ContStoryRadioButtonList" DataTextFormatString=" {0}" CellPadding="2" runat="server">
<asp:ListItem Value="0">
Search singular and continuing stories
</asp:ListItem>
<asp:ListItem Value="1">
Search only singular stories
</asp:ListItem>
<asp:ListItem Value="2">
Search only continuing stories
</asp:ListItem&g开发者_JAVA百科t;
<asp:ListItem Value="3">
Search only continuing stories with at least&nbsp; <input runat="server" id="episodetb" Value="0" style="width:50px" />
episodes
</asp:ListItem>
</asp:RadioButtonList >

Please help me with this. thx in advance


Unfortunately a ListItem object doesn't have any child controls. You could write your own control doing something similar. Basically you just have to write a <ul> tag with <li/> subitems.


You can create this using the literal control and adding the controls to a panel or placeholder.

VB

Dim list_startul as New Literal
list_startul.text = "<ul>"

Dim list_li as New Literal
lisstt_li.text = "<li><label>Hello!</label></li>"

Dim list_endul as New Literal
list_endul.text = "</ul>"

panel.controls.add(list_startul)
panel.controls.add(list_li)
panel.controls.add(list_endul)


You cannot have a server control inside a ListItem. You could have a text control beside the RadioButtonList and fake it, or you could write you own control.


You can't have HTML in a ListItem, and that's it. You'll have to make your thing out of separate radiobuttons.


One work around is to take the runat="server" off the input control. You can have client side controls in there (although the parser may suggest not). Capture the keyup of the input control with jQuery and store the value from the textbox in a server hidden field.

<asp:RadioButtonList ID="Services" runat="server">
    <asp:ListItem Text="Option 1" Value="1">
        Enter data:  <input id="test" type="text"/>
    </asp:ListItem>
<%--(...more listitems)--%>
</asp:RadioButtonList>
<asp:HiddenField ID="NewValue" runat="server />

JQuery -

$('#test').keyup(function() {
    $('#<%=NewValue.ClientID%>').val(this.value);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜