Note that there are some explanatory texts on larger screens.

plurals
  1. PORender RadioButtonList using nested divs instead of tables or flow
    text
    copied!<p>I am generating a radio button list programatically in C#.NET 3.5 and using a <code>RadioButtonList</code> in order to do so. However, something I find very frustrating is the <code>RepeatLayout</code> property, which can only be set to <code>Flow</code> or <code>Table</code>. </p> <p>Tables are for tabular data, not for displaying forms. And flow isn't helpful because it doesn't lend itself well to styling.</p> <p>What I really want is a nest of divs I can address with CSS. Can this be done?</p> <p>Some examples to illustrate what I'm talking about and example code below.</p> <p><strong>Example of flow</strong></p> <pre><code>&lt;span id="s1"&gt; &lt;input id="s1_0" type="radio" value="Answer A" name="s1"&gt; &lt;label for="s1_0"&gt;Answer A&lt;/label&gt; &lt;br&gt; &lt;input id="s1_1" type="radio" value="Answer B" name="s1"&gt; &lt;label for="s1_1"&gt;Answer B&lt;/label&gt; &lt;/span&gt; </code></pre> <p><strong>Example of table</strong></p> <pre><code>&lt;table border="0" id="s1"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="radio" value="Answer A" name="s1" id="s1_0"&gt;&lt;label for="s1_0"&gt;Answer A&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="radio" value="Answer B" name="s1" id="s1_1"&gt;&lt;label for="s1_1"&gt;Answer B&lt;/label&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p><strong>What I actually want</strong></p> <pre><code>&lt;div id="s1"&gt; &lt;div&gt; &lt;input type="radio" value="Answer A" name="s1" id="s1_0"&gt; &lt;label for="s1_0"&gt;Answer A&lt;/label&gt; &lt;/div&gt; &lt;div&gt; &lt;input type="radio" value="Answer B" name="s1" id="s1_1"&gt; &lt;label for="s1_1"&gt;Answer B&lt;/label&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>C# Code I'm using to generate the list</strong></p> <p>I know whatever the solution is, won't be as quick and easy as this, but I'm putting it here so you can get an idea of the context in which I'm using it.</p> <pre><code>RadioButtonList rbl = new RadioButtonList { RepeatLayout = RepeatLayout.Table }; foreach (ControlValue cv in MasterControl.listControlValues) { rbl.Items.Add(new ListItem(cv.name, cv.value)); } ControlContainer.Controls.Add(rbl); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload