How to check the correct radio button.
        Posted  
        
            by MrW
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by MrW
        
        
        
        Published on 2010-05-25T13:43:35Z
        Indexed on 
            2010/05/25
            13:51 UTC
        
        
        Read the original article
        Hit count: 230
        
html
|radiobutton
I have a Table containing some information that I need. All these rows also contains a column with a radio button in it so that the user is suppose to be able to check one of the rows as default.
When I'm bringing the data back from the DB and want to select the one that's currentlly the default one.
<% foreach (var item in (IEnumerable<Locale>) ViewData["Locales"]) { %>
    <tr>
        <td>
            <%= Html.Encode(item.Language.Name) %>
        </td>
        <td>
            <input type="radio" id="defaultLocale" name="defaultLocele" value="on" checked="<%= item.Default == false ? "false" : "true" %>" />
        </td>
I've also tried to do this:
<input type="radio" id="defaultLocale" name="defaultLocele" value="on" checked="<%=item.Default == false ? "" : "checked" %>" />
but nothing seems to do the right thing. I always end up with having the last row in checked, which it isn't for sure.
© Stack Overflow or respective owner