Writing Nested If condition using C# in ASP.Net

Last Reply one year ago By Shashikant

Posted one year ago

hi

I use if condition in behind code:

if (Ch3D.Checked == true)
{
    _cmd.Parameters.AddWithValue("@GenrePre", "1");

}
else
{
    if (ChOscar.Checked == true)
    {
        _cmd.Parameters.AddWithValue("@GenrePre", "2");

    }
    else
    {

        if (ChDobleF.Checked == true)
        {
            _cmd.Parameters.AddWithValue("@GenrePre", "3");

        }
    }
}

as you see I used neasted if else condition is there other code that I use it instead of neasted if else contition?

best regards

neda

 

Posted one year ago
nedash says:
if (Ch3D.Checked == true)
            {
                _cmd.Parameters.AddWithValue("@GenrePre", "1");
 
            }
            else
            {
                if (ChOscar.Checked == true)
                {
                    _cmd.Parameters.AddWithValue("@GenrePre", "2");
 
                }
                else {
 
                    if (ChDobleF.Checked == true)
                    {
                        _cmd.Parameters.AddWithValue("@GenrePre", "3");
 
                    }
                }
            }

Hi,

as per your condition your code is proper.

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html