Example of RadioButtonList control

RadioButtonList Web Server Control:

Asp.net Radio button list control give a permission to user to select an item from given list of controls.Radiobutton support data bind Programming in asp.net from database. We can also bind data it manually by input list item inside RBlist control tag. button list is a single selection radio button group.



RBList proparties

Buttonlist have a collection of items. You can determine which item is selected by selectItem property of RadioButton. we can change it's design by setting up it's  properties as like BackColor property, BorderColor property of RadioButton, BorderStyle property, BorderWidth property, CellPadding property, CellSpacing property, CssClass property, Font-Bold property of RadioButtonList, Font-Italic property, Font-Names property, Font-Overline property, Font-Size property etc. 

RBList Class: 


RadioButtonlist control
Radio Button list in .net Programming

RadioButtonList Constructor:


RadioButtonList(), is a contractor of asp.net RadioBtton it is use to creating a new Instants. It is public type means every one Access it form any where.


Properties:

CssClass property, Font-Bold property of RadioButtonList, Font-Italic property, Font-Names property, Font-Overline property, Font-Size property etc.
There are more three properties Repeat Columns, Repeat Direction and Repeat Layout which help you to place list item vertically or horizontally. 


RadioButtonList example in asp.net

First create a asp.net Web Form name RadioButtonList.aspx. I just use this RadioButtonList to place image list. When you select any option then specific image is shown in Image control. In this example of RadioButtonList use two property are important, first property AutoPostBack and second one  OnSelectedIndexChanged property. Here is the source code.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server"> 
    protected void RadioButtonList1_SelectedIndexChanged(object sender, System.EventArgs e) { 
        Image1.ImageUrl = "Images/" + RadioButtonList1.SelectedItem.Text.ToString(); 
    } 
</script> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head id="Head1" runat="server"> 
    <title>RadioButtonList example,Use of asp.net buttonlist control</title> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
        <asp:Image ID="Image1" runat="server" Height="100px"
            ImageUrl="~/Images/Flower1.jpg" Width="96px" /> 
        <br /> 
        <asp:Label ID="Label1" runat="server" Text="Select for view image"></asp:Label> 
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal" RepeatColumns="2" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged" AutoPostBack="true">  
            <asp:ListItem>Flower4.jpg</asp:ListItem> 
            <asp:ListItem>Flower3.jpg</asp:ListItem> 
            <asp:ListItem>Flower2.jpg</asp:ListItem> 
            <asp:ListItem>Flower.jpg</asp:ListItem> 
        </asp:RadioButtonList> 
    </div> 
    </form> 
</body> 
</html> 
how to use RadioButtonList  in asp.net

RadioButtonList have standard AutoPostBack property. As like other list control radiobuttonlist have an excellent event SelectedIndexChanged. so that when someone select an item it automatically post back the page and we can determine programmatically which item is selected now. for that we need to set AutoPostBack property value to true and setup a SelectedIndexChanged event. DataSourceID, DataTextField and DataValueField property help you to data bind radiobuttonlist with database. radiobuttonlist also support theme and skin.

Example of Use radiobutton list in html:

<head>
</head>
<html>
<body>
   <form id="Form1" runat="server">
      <h3>RadioButtonList Example</h3>
      <asp:RadioButtonList id=RadioButtonList1 runat="server">
         <asp:ListItem>Item 1</asp:ListItem>
         <asp:ListItem>Item 2</asp:ListItem>
         <asp:ListItem>Item 3</asp:ListItem>
         <asp:ListItem>Item 4</asp:ListItem>
         <asp:ListItem>Item 5</asp:ListItem>
         <asp:ListItem>Item 6</asp:ListItem>
      </asp:RadioButtonList>
      <p>     
      <asp:Button id="Button1"
           Text="Submit"
           OnClick="Button1_Click"
           runat="server"/>
      <p>
      <asp:Label id="Label1"
           Font-Name="Verdana"
           Font-Size="8pt"
           runat="server"/>
   </form>
</body>
</html>
Asp.net Radiobuttonlist
Html Radiobuttonlist





Related Post:

Comments

Popular posts from this blog