No C #, but I think you understand what I mean:
in codebehind page_load:
If Not IsPostBack Then Me.rbl.Items.Add(New ListItem("Alpha", "alpha")) If (useGreek()) Then Me.rbl.Items.Add(New ListItem("Beta", "beta")) Me.rbl.Items.Add(New ListItem("Gamma", "gamma")) ElseIf (useNato()) Then Me.rbl.Items.Add(New ListItem("Bravo", "bravo")) Me.rbl.Items.Add(New ListItem("Charlie", "charlie")) End If Me.rbl.Items.Add(New ListItem("Delta", "delta")) End If
If you need to check every answer because the state can change quickly, you can add Me.rbl.Items.Clear() to the beginning and remove the PostBack check.
EDIT: C #
if (!IsPostBack) { this.rbl.Items.Add(new ListItem("Alpha", "alpha")); if ((useGreek())) { this.rbl.Items.Add(new ListItem("Beta", "beta")); this.rbl.Items.Add(new ListItem("Gamma", "gamma")); } else if ((useNato())) { this.rbl.Items.Add(new ListItem("Bravo", "bravo")); this.rbl.Items.Add(new ListItem("Charlie", "charlie")); } this.rbl.Items.Add(new ListItem("Delta", "delta")); }
Because I'm not sure that you already know the codebehind model, look at the following link: MSDN: Codebehind and compilation in ASP.NET 2.0
source share