Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi everyone just wondering if it is possible to change a asp radiobuttonlist repeatdirection when screen size is smaller than 980

XML
<asp:RadioButtonList ID="RadioButtonList1"  runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" >
                                <asp:ListItem Text="Strongly&nbsp;Agree"></asp:ListItem>
                                <asp:ListItem Text="Agree"></asp:ListItem>
                                <asp:ListItem Text="Neutral"></asp:ListItem>
                                <asp:ListItem Text="Disgree"></asp:ListItem>
                                <asp:ListItem Text="Strongly&nbsp;Disgree"></asp:ListItem>

                            </asp:RadioButtonList>



please any help would be apreciated

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 4-Jun-13 4:53am
v2
Comments
Prasad Khandekar 4-Jun-13 9:20am    
I don't think it's possible to do this. It's purely a WebControl property with no HTML equivalent.
Sergey Alexandrovich Kryukov 4-Jun-13 10:23am    
Oh, thank you. I answered formally, did not pay attention for the particular attribute mentioned. Will remove my answer...
—SA
Hi Sergey Alexandrovich Kryukov,

I did a research on this and finally came up with a solution.
Please take a look at my answer.

Thanks,
Tadit
Hi Prasad Khandekar,

I did a research on this and finally came up with a solution. Please take a look at my answer.

Thanks,
Tadit
OriginalGriff 4-Jun-13 10:53am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

I finally did it... Hurray :) Feeling happy.

Observation

I observed the html generated for both the types (Vertical and Horizontal) of RepeatDirection property for RadioButtonList Control.

What I found is described below.


  1. Case - 1 (RepeatDirection="Horizontal")
    XML
    <span id="RadioButtonList1">
        <input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Strongly Agree" />
        <label for="RadioButtonList1_0">Strongly Agree</label>
        
        <input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Agree" />
        <label for="RadioButtonList1_1">Agree</label>
        
        <input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Neutral" />
        <label for="RadioButtonList1_2">Neutral</label>
        
        <input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="Disgree" />
        <label for="RadioButtonList1_3">Disgree</label>
        
        <input id="RadioButtonList1_4" type="radio" name="RadioButtonList1" value="Strongly Disgree" />
        <label for="RadioButtonList1_4">Strongly Disgree</label>
    </span>


  2. Case - 2 (RepeatDirection="Vertical")

    Note:- Here we can check that Break (br) tags are getting added after labels to make the RadioButtons Vertically aligned.
    XML
    <span id="RadioButtonList1">
        <input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="Strongly Agree" />
        <label for="RadioButtonList1_0">Strongly Agree</label><br />
        
        <input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="Agree" />
        <label for="RadioButtonList1_1">Agree</label><br />
        
        <input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="Neutral" />
        <label for="RadioButtonList1_2">Neutral</label><br />
        
        <input id="RadioButtonList1_3" type="radio" name="RadioButtonList1" value="Disgree" />
        <label for="RadioButtonList1_3">Disgree</label><br />
        
        <input id="RadioButtonList1_4" type="radio" name="RadioButtonList1" value="Strongly Disgree" />
        <label for="RadioButtonList1_4">Strongly Disgree</label>
    </span>



Logic

Now my logic would be removing and adding these Break (br) tags as per the RepeatDirection.


  • If Break tags are found (means currently it is Vertical) after the labels, then they will be removed to make it Horizontal.
  • Else if Break tags are not found(means currently it is Horizontal), then they will be added to make it Vertical.


Demo

[Demo] Change Repeat Direction of asp RadioButtonList[^].

Take a look at the Demo how I achieved this.


Thanks a lot for the question. I learned some stuff due to this.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 4-Jun-13 15:31pm    
That's nice, a 5. I guess you tested it, right?
—SA
Thanks a lot Sergey Alexandrovich Kryukov... :)

Yes, tested it and also created the demo. You can check.
Sergey Alexandrovich Kryukov 4-Jun-13 23:05pm    
Very nice, both the code and its operation.
Cheers,
—SA
Cheers... High Five. :)
Prasad Khandekar 5-Jun-13 4:04am    
Very well done. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900