If statement
IfStatementExample.aspx
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) {
string li = RadioButtonList1.SelectedItem.Text;
if (li == "Pink") {
RadioButtonList1.BackColor = System.Drawing.Color.HotPink;
RadioButtonList1.ForeColor = System.Drawing.Color.AntiqueWhite;
RadioButtonList1.BorderColor = System.Drawing.Color.LightPink;
}
else if (li == "Green")
{
RadioButtonList1.BackColor = System.Drawing.Color.SeaGreen;
RadioButtonList1.ForeColor = System.Drawing.Color.AntiqueWhite;
RadioButtonList1.BorderColor = System.Drawing.Color.LightGreen;
}
else {
RadioButtonList1.BackColor = System.Drawing.Color.LightSeaGreen;
RadioButtonList1.ForeColor = System.Drawing.Color.LightYellow;
RadioButtonList1.BorderColor = System.Drawing.Color.DarkGreen;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>asp.net if statement example: if(){} else if(){} else{}</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:Red">If Statement Example</h2>
<asp:RadioButtonList
ID="RadioButtonList1"
runat="server"
RepeatColumns="3"
BorderWidth="1"
AutoPostBack="true"
OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"
BackColor="LightSeaGreen"
ForeColor="LightYellow"
BorderColor="DarkGreen"
>
<asp:ListItem>Red</asp:ListItem>
<asp:ListItem>Blue</asp:ListItem>
<asp:ListItem>Coral</asp:ListItem>
<asp:ListItem>Green</asp:ListItem>
<asp:ListItem>DarkMagenta</asp:ListItem>
<asp:ListItem>Pink</asp:ListItem>
<asp:ListItem>Gold</asp:ListItem>
</asp:RadioButtonList>
</div>
</form>
</body>
</html>



