How to set asp.net radiobuttonlist margin with asp.net C# example

Category > ASP.NET || Published on : Sunday, September 7, 2014 || Views: 9029 || asp net validate radiobuttonlist asp net radiobuttonlist horizontal asp net radiobuttonlist onselectedindexchanged jquery asp net radiobuttonlist asp net radiobuttonlist onclientclick


In this tutorial, We are going to learn How to set asp.net radiobuttonlist margin with asp.net C# example

RadioButtonList is an asp.net list web server control that render a single selection radio button group in web browser. the following asp.net c# example source code demonstrate us how can we apply margin in a radiobuttonlist control. actually in this example code we will apply margin css style to a radiobuttonlist's each item.

radiobuttonlist web server control have no built in property to set margin in radiobuttonlist control or each item in radiobuttonlist. so we need to take help from css style. radiobuttonlist items collection contains ListItem objects. we can attach any css style to a ListItem object using Attributes property as Attributes.CssStyle.Add(). this Add() method allow us to attach any css style by name value pair to a ListItem object.

in this example we iterate through the radiobuttonlist items collection using foreach loop and attach a margin css style to its each item. here we applied 25 pixel left and right margin for each item in a radiobuttonlist server control. in this way we can assign different margin value for different item in a radiobuttonlist. event we can apply margin for any specific item in a radiobuttonlist.


Step 1: Create a ASP.NET empty Web Application

Step 2: Create a webform “Default.aspx” and write the following codes.

<%@ Page Language="C#" AutoEventWireup="true"%>    
      
        
        
        
"http://www.w3.org/1999/xhtml">        
"Head1" runat="server">        
    How to <span style="color:Blue">set</span> asp.net radiobuttonlist margin with asp.net C# example
        
        
    "form1" runat="server">        
    

How to set asp.net radiobuttonlist margin with asp.net C# example


"550" align="left" color="Gainsboro" /> "Label1" runat="server" Font-Size="Large" Width="350" Text="select an item from radiobuttonlist" >

"RadioButtonList1" runat="server" RepeatDirection="Vertical" AutoPostBack="true" RepeatLayout="Flow" BorderColor="SkyBlue" BorderWidth="1" >

Step 3:  Run the application or press the F5 Key on the keyboard. You will get the following output as below to set asp.net radiobuttonlist margin with asp.net C# example

Conclusion:-
so In this tutorial, we have learned How to set asp.net radiobuttonlist margin with asp.net C# example. Happy Coding!!!!

Download Source Codes