Check Radio Button List Item from bool value

Hi,

I'm trying to check a radio button depending on a boolean value that I have but I don't see any online resources which can help me do so.

Here is my code:

<RadzenRadioButtonList @bind-Value="@value" TValue="int">

<RadzenRadioButtonListItem Text="sayHello" Value= "1" (Close bracket)
<RadzenRadioButtonListItem Text="sayBye" Value="2" (Close bracket)
</item

@code {
bool sayHello = true;
bool sayBye = false;
}

If the sayHello is true, I want to check the first radzenRadiobutton, else I will check the other button. I will have buttons to change the sayHello and sayBye variables as well.

Please ignore the obvious syntax errors as the code dissapears when I type close brackets.
Could anyone please advise me on how I can do this please? Thank you!

Hi @420BlazorIt ,

The Value of the RadzenRadioButtonList should be set to the Value of the item you want to be selected - either 1 or 2 according to your declaration. You can also check the forum FAQ for tips how to format code snippets.

yes, my value is set to 1

int value = 1

So how do I check a radzenradiobuttonlist item from the bool value of sayHello and sayBye?

Here is my code:

<RadzenRadioButtonList @bind-Value="@value" TValue="int" Name="test1">
        <Items>
            <RadzenRadioButtonListItem Text="Say hello" Value="1"></RadzenRadioButtonListItem>
            <RadzenRadioButtonListItem Text="Say bye" Value="2"></RadzenRadioButtonListItem>    
        </Items>
    </RadzenRadioButtonList>

@code{
int value = 1;
bool sayHello = true;
bool sayBye = false;
}

I want to check one of the radio button list item depending on the bool value sayHello or sayBye.
I hope you can understand this better.

Hi @420BlazorIt ,

You need to set the value property to 1 or 2 depending on the values of sayHello and sayBye.

Hey @korchev

Does the 1 and 2 mean checked/unchecked respectively?

<RadzenRadioButtonListItem Text="Say hello" Value="1"></RadzenRadioButtonListItem>
            <RadzenRadioButtonListItem Text="Say bye" Value="2"></RadzenRadioButtonListItem>

No. Check my initial reply: