How to iterate asp.net radiobuttonlist items using C# foreach loop with example

Category > ASP.NET || Published on : Friday, September 26, 2014 || Views: 17498 || radiobuttonlist ASP.NET radiobuttonlist items using C# foreach loop


In this tutorial, We are going to learn how can we iterate through the radiobuttonlist items using foreach statement with C# example

Step 1: Create a ASP.NET empty Web Application

Step 2: Create a webform “Default.aspx” and write the following codes.
RadioButtonList is an asp.net list web server control. radiobuttonlist control contains a collection of ListItem objects. we can iterate through this items collection using foreach loop.

The following asp.net c# example code demonstrate us how can we iterate through the radiobuttonlist items using foreach statement. The foreach statement cannot be used to add or remove items from the source collection. but we can change items any property value in a radiobuttonlist control using foreach loop. in this example we iterate through a radiobuttonlist items collection to display its items text, value and selected state using foreach loop.

we can break out of the foreach loop at any point using break keyword or step to the next iteration in the loop by using the continue keyword.

<%@ Page Language="C#" AutoEventWireup="true" %>



"http://www.w3.org/1999/xhtml">
"Head1" runat="server">
    How to iterate asp.net radiobuttonlist items <span style="color:Blue">using</span> C# <span style="color:Blue">foreach</span> loop with example
    


    "form1" runat="server">
    

How to iterate asp.net radiobuttonlist items using C# foreach loop with example


"Label1" runat="server" Font-Size="Large" Width="350">

"RadioButtonList1" runat="server" RepeatDirection="Vertical" AutoPostBack="true" Border="1" BorderColor="LightGray">

Step 3:  Run the application or press the F5 Key on the keyboard. You will get the following output as how can we iterate through the radiobuttonlist items using foreach statement with C# example

Conclusion:-
so In this tutorial, we have learned how can we iterate through the radiobuttonlist items using foreach statement with C# example. Happy Coding!!!!

Download Source Codes