views:

32

answers:

1

When i tries to bind a radio button in a datalist it becomes multiselect as its name property becomes different even when i used GroupName to be same.

How can i make it act as radio button only.

   <asp:DataList ID="dlRoomNo" runat="server" RepeatColumns="4">
        <ItemTemplate>
           <div class="orboxfour">
                <ul class="boxfour">
                    <li>
                        <asp:RadioButton ID="rdoRoomNo" GroupName="roomNo"
 Text='<%#Eval("Room No")%>' runat="server" />
                    </li>
                </ul>
           </div>                       
        </ItemTemplate>
    </asp:DataList>
A: 

There's a number of suggestions in the answers to this question.


I've solved it with a bit of jQuery, though the way I did it probably isn't the best way!

In my markup, I have a script block with

function SetUniqueRadioButton(current)
{
    $('input:radio').attr('checked', false);

    current.checked = true;
}

and then attached the script to a radio button in my code-behind in the ItemDataBound event

String uniqueRadioButtonScript;
RadioButton radioButton;

uniqueRadioButtonScript = "javascript:SetUniqueRadioButton(this);";

if (e.Row.RowType == DataControlRowType.DataRow)
{
    radioButton = (RadioButton)e.Row.FindControl("MyRadioButton");

    radioButton.Attributes.Add("onclick", uniqueRadioButtonScript)
}
PhilPursglove