выбор элемента
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> div { float: left; } </style> </head> <body> <form id="form1" runat="server"> <div> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Value="#FF0000">Red</asp:ListItem> <asp:ListItem Value="#00FF00">Green</asp:ListItem> <asp:ListItem Value="#0000FF">Blue</asp:ListItem> </asp:RadioButtonList> </div> <div> <asp:Button ID="Button1" runat="server" Text="OK" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="Clear" OnClick="Button2_Click" /> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> <asp:Label ID="Label3" runat="server" Text=""></asp:Label> </div> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> div { float: left; } </style> </head> <body> <form id="form1" runat="server"> <div> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server"> <asp:ListItem Value="#FF0000">Red</asp:ListItem> <asp:ListItem Value="#00FF00">Green</asp:ListItem> <asp:ListItem Value="#0000FF">Blue</asp:ListItem> </asp:RadioButtonList> </div> <div> <asp:Button ID="Button1" runat="server" Text="OK" OnClick="Button1_Click" /> <asp:Button ID="Button2" runat="server" Text="Clear" OnClick="Button2_Click" /> <asp:Label ID="Label1" runat="server" Text=""></asp:Label> <asp:Label ID="Label2" runat="server" Text=""></asp:Label> <asp:Label ID="Label3" runat="server" Text=""></asp:Label> </div> </div> </form> </body> </html>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = RadioButtonList1.SelectedIndex.ToString(); Label2.Text = RadioButtonList1.SelectedItem.Text; Label3.Text = RadioButtonList1.SelectedItem.Value; } protected void Button2_Click(object sender, EventArgs e) { Label1.Text = string.Empty; Label2.Text = string.Empty; Label3.Text = string.Empty; RadioButtonList1.ClearSelection(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = RadioButtonList1.SelectedIndex.ToString(); Label2.Text = RadioButtonList1.SelectedItem.Text; Label3.Text = RadioButtonList1.SelectedItem.Value; } protected void Button2_Click(object sender, EventArgs e) { Label1.Text = string.Empty; Label2.Text = string.Empty; Label3.Text = string.Empty; RadioButtonList1.ClearSelection(); } }
событие при выборе элемента
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> div { float: left; } .red { background-color: #F00; } .green { background-color: #0F0; } .blue { background-color: #00F; } .a { display: none; } .b { display: block; } #Panel1 { height: 80px; width: 80px; } </style> </head> <body> <form id="form1" runat="server"> <div> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem Value="#FF0000">Red</asp:ListItem> <asp:ListItem Value="#00FF00">Green</asp:ListItem> <asp:ListItem Value="#0000FF">Blue</asp:ListItem> <asp:ListItem Value="clear">Clear</asp:ListItem> </asp:RadioButtonList> </div> <div> <asp:Panel ID="Panel1" runat="server" CssClass="a"></asp:Panel> </div> </div> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta charset="utf-8" /> <title></title> <style> div { float: left; } .red { background-color: #F00; } .green { background-color: #0F0; } .blue { background-color: #00F; } .a { display: none; } .b { display: block; } #Panel1 { height: 80px; width: 80px; } </style> </head> <body> <form id="form1" runat="server"> <div> <div> <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged"> <asp:ListItem Value="#FF0000">Red</asp:ListItem> <asp:ListItem Value="#00FF00">Green</asp:ListItem> <asp:ListItem Value="#0000FF">Blue</asp:ListItem> <asp:ListItem Value="clear">Clear</asp:ListItem> </asp:RadioButtonList> </div> <div> <asp:Panel ID="Panel1" runat="server" CssClass="a"></asp:Panel> </div> </div> </form> </body> </html>
Default.aspx.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if(RadioButtonList1.SelectedItem.Value == "#FF0000") { Panel1.CssClass = "b red"; } else if(RadioButtonList1.SelectedItem.Value == "#00FF00") { Panel1.CssClass = "b green"; } else if(RadioButtonList1.SelectedItem.Value == "#0000FF") { Panel1.CssClass = "b blue"; } else if(RadioButtonList1.SelectedItem.Value == "clear") { Panel1.CssClass = "a"; RadioButtonList1.ClearSelection(); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e) { if(RadioButtonList1.SelectedItem.Value == "#FF0000") { Panel1.CssClass = "b red"; } else if(RadioButtonList1.SelectedItem.Value == "#00FF00") { Panel1.CssClass = "b green"; } else if(RadioButtonList1.SelectedItem.Value == "#0000FF") { Panel1.CssClass = "b blue"; } else if(RadioButtonList1.SelectedItem.Value == "clear") { Panel1.CssClass = "a"; RadioButtonList1.ClearSelection(); } } }