How to set checked value for radio input tag using ASP.Net?

I have this radio tag:

<input name="phoneRadio" class="phoneRadio" id="rbDefaultPhone" 
    type="radio" checked="<%# GetIsChecked(Eval("IsDefault")) %>"/>

in the repeater and GetIsChecked is a C # function that returns a bool value, my problem is that it does not affect the checked value of the radio button correctly, Does anyone know how to fix this?

+3
source share
2 answers

Just having an attribute checkedon is inputenough to test it. In HTML, you just need to have checkedit in XHTML, it should be checked="checked", but in any case you want to exclude the entire attribute if it is not set.

GetIsChecked ( ) "checked='checked'", String.Empty. , checked ( ). :

<input name="phoneRadio" class="phoneRadio" id="rbDefaultPhone" type="radio" <%# GetChecked(Eval("IsDefault"))%> />

 

protected string GetChecked(object isDefault)
{
    return (bool)isDefault ? "checked='checked'" : string.Empty;
}
+8

Bdukes . , , , checked=checked,

checked
checked=""
checked="checked"

.

, 'IsDefault' bool, .

<input name="phoneRadio" class="phoneRadio" id="rbDefaultPhone"  type="radio" 
 checked='<%#Eval("IsDefault")%>'

.

0

Source: https://habr.com/ru/post/1704595/


All Articles