0

I'm trying to set a value from the database into a Html component, the code is as follow:

<asp:RadioButtonList ID="rbFiltroCostesPre" runat="server" AutoPostBack="false" Width="286px">
   <asp:ListItem Selected="True" Value="A">All</asp:ListItem>
   <asp:ListItem Value="Greater">First 10</asp:ListItem>
   <asp:ListItem Value="GreaterThan">Greater than: &lt;input ID=&quottxtGreaterThan&quot; type=&quot;text&quot; &gt;</asp:ListItem>                                              
</asp:RadioButtonList>   

The last ListItem has a Html tag inside, like:

<input id="txtGreaterThan" type="text"/>   

, which has been transform by the Visual Web Development IDE.

Can I set it's value dynamically from the codebehind? Thx.

0

1 Answer 1

1

Sorry, but you can't do that with the managed ListItem control. What's happening in your page is it's setting the Text value of your ListItem with Greater than: &lt;input ID=&quottxtGreaterThan&quot; type=&quot;text&quot; &gt;.

What you could do is to use a RadioButton instead of a RadioButtonList and place a TextBox control next to the RadioButton. This would allow you to access it server-side.

Sign up to request clarification or add additional context in comments.

3 Comments

I'm not sure that's true. If I look the source code from the web page, the generated code, for the last item is: <label for="rbFiltroCostesPre_2"> Coste mayores que: <input id="txtCostesMayoresQue" class="numeric" type="text" name="txtCosteMayorQue" runat="server" style="width: 57px"> % </label> So you can see I still have an input with Id. Thx
That's because you're "faking it out" by placing HTML inside your text of the ListItem. So it will render the HTML, but it will not be a managed control. I've updated my answer with a suggestion on using a managed control.
Yes¡ the use of radioButton instead of radioButtonList does the trick. THKX. I would vote you, but I can't. Thanks again

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.