Usefull Properties
1. RepeatDirection
2. RepeatColumns
3. RepeatLayout
4. SelectedItem
5. SelectedIndex
Example :-
WebForm1.aspx :-
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="_27_RadiobuttonList.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
RepeatDirection="Horizontal">
<asp:ListItem Value="1">Red</asp:ListItem>
<asp:ListItem Value="2">Green</asp:ListItem>
<asp:ListItem Value="3">Blue</asp:ListItem>
<asp:ListItem Value="4">Orange</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Clear Selection" />
</div>
</form>
</body>
</html>
WebForm1.aspx.cs :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace _27_RadiobuttonList
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (RadioButtonList1.SelectedValue!=null)
{
Response.Write("Text = " + RadioButtonList1.SelectedItem.Text + ", ");
Response.Write("Value = " + RadioButtonList1.SelectedItem.Value + ", ");
Response.Write("Index = " + RadioButtonList1.SelectedIndex.ToString());
Response.Write("<br/>");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
RadioButtonList1.SelectedIndex = -1;
}
}
}
No comments:
Post a Comment