ASPNET单选按钮控件RadioButton常用属性和方法介绍
Asp.Net常用控件有哪些,有什么作用。

常⽤控件有哪些,有什么作⽤。
打开VS010,我们可以看到它提供的Web控件为:标准,数据,验证,导航,登陆,Webparts(⽹页组件),AJAX Extension,Dynamic(动态) Data,Reporting(报表),HTML,General(常规,综合的)这⼏类。
⼀.standard1、Label控件:标签,主要作⽤在于显⽰⽂字讯息,标签控件显⽰的⽂字不能直接进⾏修改,要修改的话只能在设计阶段进⾏!常⽤属性:Id:此控件名称 Text:要显⽰的⽂字信息 ToolTip:⿏标放在控件上时显⽰的提⽰信息 Visible:运⾏时是否可见2、TextBox:⽂本框:既可以⽤来显⽰⽂字,还能够在⽂字框中输⼊⽂字常⽤属性:AutoPostBack:⽂本修改后是否⾃动回发到服务器 MaxLength:可输⼊的最⼤字符数 TextMode:⾏为模式,有SingleLine,MultiLine,Password三个值3、Button:按钮常⽤属性:CausesValidation:是否启动验证点击Button按钮控件时会触发click和command事件,两者的区别是,如果要激发command事件,需要设置commandArgument、commandName属性值,⽽且可以对多个button控件同时指定⼀个command事件,通过CommandName的值不同来触发不同的操作;但是click事件,每⼀个控件只有⼀个⽅法,⽽且不能同⽤例。
4、LinkButton控件:在页⾯上显⽰为⼀个超链接5、ImageButton控件:以图⽚形式显⽰ ImageUrl属性指定图⽚路径6、HyperLink:超链接控件 NavigateUrl属性指定定位到的Url7、Dropdown List:下拉菜单8、ListBox列表框:常⽤属性:1、BackColor 属性:⽤于显⽰ListBox控件中的⽂本和图形的背景颜⾊,默认为⽩⾊(Window)2、BorderStyle 属性:控制在列表框ListBox周围绘制的边框的类型,其枚举值为下⾯三个:BorderStyle.None——⽆边框BorderStyle.FixedSingle——单⾏边框BorderStyle.Fixed3D——三维边框默认值为BorderStyle.Fixed3D。
winform 单选框用法

Winform 单选框用法什么是WinformWinform是指Windows窗体应用程序,是一种用于开发Windows桌面应用程序的技术。
它是微软公司提供的一种基于.NET框架的图形用户界面(GUI)开发工具,使用C#或等编程语言进行开发。
Winform提供了丰富的控件库,包括按钮、文本框、标签、单选框等,可以通过拖拽控件的方式快速搭建用户界面,并通过编程实现各种功能和交互。
在Winform应用程序中,单选框(RadioButton)是一种常用的控件,它允许用户从多个选项中选择一个。
本文将详细介绍Winform单选框的用法,包括创建、设置属性、事件处理等。
创建Winform应用程序在开始讲解Winform单选框的用法之前,我们先来创建一个Winform应用程序。
首先,打开Visual Studio(我使用的是Visual Studio 2019),选择创建新项目。
在模板选择中,选择Visual C# -> Windows桌面 -> Windows Forms应用程序。
接下来,选择项目名称和存储位置,并点击“创建”按钮。
完成上述步骤后,Visual Studio会自动生成一个默认的Winform应用程序。
添加单选框控件要使用单选框控件,首先需要将其添加到窗体上。
在Visual Studio的工具箱中,可以找到单选框控件(RadioButton)。
将其拖拽到窗体上的合适位置。
添加单选框控件后,可以在窗体设计器中对其进行调整和设置。
设置单选框属性Winform单选框控件有一些常用的属性,可以通过设置这些属性来自定义单选框的外观和行为。
Text属性Text属性用于设置单选框的显示文本。
可以通过在属性窗口中直接修改Text属性的值,或者在代码中通过赋值来设置。
radioButton1.Text = "选项1";Checked属性Checked属性用于设置单选框的选中状态。
RadioButtonList定义和用法.doc

RadioButtonList定义和用法RadioButtonList 控件用于创建单选按钮组。
创建一组单选按钮。
此控件支持绑定到数据源。
RadioButtonList 控件中的每个可选项是通过 ListItem 元素来定义的!提示:该控件支持数据绑定!属性<asp:RadioButtonListAccessKey="string"AppendDataBoundItems="True|False"AutoPostBack="True|False"BackColor="color name|#dddddd"BorderColor="color name|#dddddd"BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge| Inset|Outset"BorderWidth="size"CausesValidation="True|False"CellPadding="integer"CellSpacing="integer"CssClass="string"DataMember="string"DataSource="string"DataSourceID="string"DataTextField="string"DataTextFormatString="string"DataValueField="string"Enabled="True|False"EnableTheming="True|False"EnableViewState="True|False"Font-Bold="True|False"Font-Italic="True|False"Font-Names="string"Font-Overline="True|False"Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium| Large|X-Large|XX-Large"Font-Strikeout="True|False"Font-Underline="True|False"ForeColor="color name|#dddddd"Height="size"ID="string"OnDataBinding="DataBinding event handler"OnDataBound="DataBound event handler"OnDisposed="Disposed event handler"OnInit="Init event handler"OnLoad="Load event handler"OnPreRender="PreRender event handler"OnSelectedIndexChanged="SelectedIndexChanged event handler"OnTextChanged="TextChanged event handler"OnUnload="Unload event handler"RepeatColumns="integer"RepeatDirection="Horizontal|Vertical"RepeatLayout="Table|Flow"runat="server"SelectedIndex="integer"SelectedValue="string"SkinID="string"Style="string"TabIndex="integer"TextAlign="Left|Right"ToolTip="string"ValidationGroup="string"Visible="True|False"Width="size"><asp:ListItemEnabled="True|False"Selected="True|False"Text="string"Value="string"/></asp:RadioButtonList>备注:RadioButtonList 控件使您能够创建单项选择的单选按钮组,可以通过绑定到数据源动态生成这个组。
AspNET控件详解

选择组件—checkbox
• 属性说明: • Checked:若为True,表示CheckBox是被选 择的,若为False,则不被选择。 • TextAlign:取值为right,字靠右排列,为 left,靠左排列。 • Text:CheckBox的文字内容。
选择组件—checkbox
• 事件说明: • OnCheckedChanged:若 AutoPostBack=True,则当CheckBox的选 择框被打勾或取消打勾都会触发 CheckedChanged事件。
RadioButton示例
<%@ page language="C#" debug="true"%> <html> <head> <title>RadioButton</title> </head> <body> <form id="CH6_11" method="post" runat="Server"> <asp:Label id="lblTitle1" runat="Server">血型:</asp:Label><br> <asp:RadioButton runat="server" id="rdoCH61" AutoPostBack=True GroupName="Blood" TextAlign="Right" Text="A" OnCheckedChanged="RadioButton_Changed"> </asp:RadioButton><br> <asp:RadioButton runat="server" id="rdoCH62" AutoPostBack=True GroupName="Blood" TextAlign="Right" Text="B" OnCheckedChanged="RadioButton_Changed"> </asp:RadioButton><br>
ASP.NET中RadioButtonList绑定后台数据后触发点击大事_

中RadioButtonList绑定后台数据后触发点击大事_本文实例为大家分享了RadioButtonList绑定后台数据,触发点击大事的方法首从前台页面放置一个RadioButtonList 控件asp:RadioButtonList runat="server" ID="RadioButtonList1" BorderStyle="None" RepeatColumns="3" CssClass=""RepeatLayout="Flow" AutoPostBack="true" OnSelectedIndexChanged="RadioButtonList1_SelectedIn dexChanged"/asp:RadioButtonList.cs文件后台绑定数据namespace BTApp{public partial class Technology : System.Web.UI.Page {string Id;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack)AspNetPager1.PageSize = 10;if (Request.QueryString["Id"] != null){Id = Request.QueryString["Id"];}else{ Id = ""; }GetDataBind(Id);DropDownListDataBind();}}//RadioButtonList绑定后台数据private void DropDownListDataBind(){ExpertInfoBLL bll = new ExpertInfoBLL();DataTable dt = bll.GetDepInfo();foreach (DataRow dr in dt.Rows){RadioButtonList1.Items.Add(dr["Name"].ToString());/ /循环读出数据库的数据this.RadioButtonList1.DataSource = dt;this.RadioButtonList1.DataTextField = "Name";this.RadioButtonList1.DataValueField = "Id";this.RadioButtonList1.RepeatDirection = RepeatDirection.Horizontal;this.RadioButtonList1.DataBind();}private void GetDataBind(string Id){//这里写解码和数据库返回结果TechnologyBLL bll = new TechnologyBLL();string strWhere = " 1=1 ";if (Id != "" Id != null){strWhere += string.Format(" and a.Depinfo_Id = '{0}'", Id);}AspNetPager1.RecordCount = bll.GetCountList(strWhere);//绑定数据DataTable dt =bll.GetList((AspNetPager1.CurrentPageIndex - 1) * AspNetPager1.PageSize, AspNetPager1.PageSize, strWhere, "CreateTime");this.Repeater1.DataSource = dt;this.Repeater1.DataBind();}protected void AspNetPager1_PageChanged(object sender, EventArgs e){GetDataBind(Id);}//依据选择单选按钮的不同id,触发大事protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e){string Id;Id = RadioButtonList1.SelectedValue;GetDataBind(Id);}}}TechnologyBLL 层的方法namespace BTAppBLL{public class TechnologyBLL{TechnologyDAL dal = new TechnologyDAL();public DataTable GetList(int startPage, int pageSize, string where, string orderby){DataTable dTable = dal.GetList(startPage, pageSize, where, orderby);return dTable;}public int GetCountList(string where){int record = dal.GetCountList(where);return record;}public DataTable GetListShow(string TechnologyId) {DataTable dTable = dal.GetModel(TechnologyId);return dTable;public DataTable GetPicture(string TechnologyId) {DataTable dTable = dal.GetPicture(TechnologyId); return dTable;}}}TechnologyDAL层的方法namespace BTAppDAL{public class TechnologyDAL{public DataTable GetList(int startPage, int pageSize, string where, string orderby){string strSql = string.Format("SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effec t,a.MainPoint,a.AppropriateArea,a.Attention,a.Creat eTime,a.CreatUser,a.UpdateTime, FROM Technology AS a \n" +"left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id"where a.IsActive='1' and {0} ", where);string proc = "proc_CommonPagerWithStatement"; SqlConnection con = SqlDbHelper.Connection;SqlParameter[] sp = { new SqlParameter("@intStartIndex", startPage),new SqlParameter("@intPageSize", pageSize), new SqlParameter("@varStatement", strSql),new SqlParameter("@varSortExpression", orderby+" DESC") };DataTable dt = SqlDbHelper.GetDataSet(proc, sp, con);return dt;}public int GetCountList(string where){int countRecord = 0;string strSql = string.Format("select COUNT(TechnologyId) as countRecord from(SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effec t,a.MainPoint,a.AppropriateArea,a.Attention,a.Creat eTime,a.CreatUser,a.UpdateTime, FROMTechnology AS a \n" +"left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id \n" +"where a.IsActive='1' and {0} ) as c", where); SqlConnection con = SqlDbHelper.Connection;try{if (con.State == System.Data.ConnectionState.Closed)con.Open();DataTable dt = SqlDbHelper.GetDataTable(strSql); if (dt.Rows.Count 0)countRecord = int.Parse(dt.Rows[0]["countRecord"].ToString());}catch (Exception){throw;}finally{if (con.State == ConnectionState.Open)con.Close();}}return countRecord;}public DataTable GetModel(string TechnologyId) {string strSql = string.Format("SELECT a.TechnologyId,a.TechnologyName,a.Summarize,a.Effec t,a.MainPoint,a.AppropriateArea,a.Attention,a.Creat eTime,a.CreatUser,a.UpdateTime, FROM Technology AS a \n" +"left join Sys_DepInfo AS b ON a.Depinfo_Id=b.Id \n" +"where a.IsActive='1' and a.TechnologyId = '{0}' ", TechnologyId);DataTable dataTable = SqlDbHelper.GetDataTable(strSql);return dataTable;}public DataTable GetPicture(string TechnologyId)string strSql = string.Format("SELECT TOP 5 a.Files_Id,a.Files_Name,a.Files_Path FROM _Files AS a \n" +"LEFT JOIN dbo.Technology AS b ON a.ForeignKey_Id=b.TechnologyId \n" +"WHERE b.IsActive=1 and a.ForeignKey_Id = '{0}' ", TechnologyId);DataTable dataTable = SqlDbHelper.GetDataTable(strSql);return dataTable;}}}ExpertInfoBLL 层的方法public DataTable GetDepInfo(){DataTable dTable = dal.GetDepInfo();return dTable;}ExpertInfoDAL层的方法public DataTable GetDepInfo(){try{StringBuilder str = new StringBuilder(@"SELECT Id,Name FROM dbo.Sys_DepInfo WHERE Is_Active='1' AND DepinfoType='1'");DataTable data = SqlDbHelper.GetDataTable(str.ToString());if (data.Rows.Count 0){return data;}else{return null;}}catch (Exception){return null;}}在页面加载的时候调用DropDownListDataBind()方法触发RadioButtonList的点击大事strong protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e){string Id;Id = RadioButtonList1.SelectedValue;GetDataBind(Id);}/strong既可以实现点击某个单选按钮,并触发大事。
ASP.NET控件(一)

使用控制权转移控件
Button 控件
16
ImageButton 控件
Hyperlink 控件
选择控件
有四种类型的选择控件: CheckBox –为用户提供一种方法在 true/false、yes/no
或 on/off 选项之间切换 RadioButton - 用于只从选项列表中选择一个选项 DropdownList - 允许用户从预定义列表中选择一项 ListBox - 允许用户从预定义列表中选择一项或多项
28
有效性验证
用户注册时,输入了不合标准的信息,怎么办?
后台手写验证代码 页面回传,用户体验不好
使用javascript脚本进行验证 不安全,与浏览器相关
提供了验证控件
轻松实现用户输入的验证,且与用户浏览器无关 由在客户端或服务器中运行的验证代码执行 多种验证控件,验证数据更加简单方便
验证控件的使用方式
验证控件可以和在Web窗体页中处理的任意控件一起使用, 比如,HTML服务器控件或 Web服务器控件等。 添加——编程人员像添加其他服务器控件那样向窗体 添加验证控件。 关联——每个验证控件都会关联到一个或多个页面上 其他地方的输入控件(服务器控件)。 设置验证条件——验证控件便根据验证条件的要求测 试用户的输入值是否通过测试的属性。编程人员可以 使用自己的代码来测试页和单个控件的状态。如果检 测到状态无效,就略过更新。 显示错误——检测到错误的验证控件随后将生成显示 在页面上的错误信息。
HTML 标签
runat="server"
HTML 服务器控件
WEB服务器端控件是一个抽象对象模板,不仅 有一般表单类控件,还有ASP .NET的专用控件, 如日历控件等。
第2章 ASP NET常用服务器标准控件2

③ 编写事件代码。 【演练2-6】代码
3.ListBox控件和DropDownList控件 ListBox(列表框)控件和DropDownList(下拉列表框)控 件是用于向用户提供输入数据选项的控件,其外观分别如 图2-19和图2-20所示。从图中可以看出,ListBox控件和 DropDownList控件都是以列表的形式向用户提供选项的, 但DropDownList控件可以将选项折叠起来,只有在用户单 击其右侧的下拉按钮 时才显示选项列表,节省了显示空 间。
② 单击“添加”按钮向单选按钮组中添加成员。在每个成 员名称之前带有一个数字编号,该编号为成员控件的索引 号(Index)。可通过SelectedIndex属性获取或设置 RadioButtonList控件中被选定成员的索引号。 ③ 选择此新项,然后在右侧列表框中设置Text、Value、 Selected等属性值。最多可以为该项指定4个可能的属性, 见表2-16。
向Web页添加一个RadioButtonList控件,然后向该控件添加 列表项,操作方法如下。 ① 从工具箱的“标准”选项卡中,将RadioButtonList控件 拖到页面上。 ② 可以在“属性”窗口中,设置TextAlign属性来更改标题 的方向,设置RepeatDirection来更改控件的布局,指定各 项的排序方式:Vertical(垂直,默认)或Horizontal(水平 )。 ③ 可以使用以下3种方法向列表服务器控件添加项: 在设计时添加静态项。 以编程方式在运行时添加项。 使用数据绑定添加项,将在后面章节中详细介绍。
在程序中可以用“控件名称.SelectedItem.Value”获取被选 中按钮的选项值,用“控件名称.SelectedItem.Text”获取被 选中按钮旁显示的文本。
.NET基本控件

课程目标
掌握CheckBox控件的使用 掌握RadioButton控件的使用 掌握 RadioButtonList控件的使用 掌握DropDownList控件的使用
CheckBox 控件-设计界面
拖动控件到Web设计界面
CheckBox 控件-属性
属性按字母排序 事件
属性
属性按分类排序 复选框显示文字 复选框名称 ►用于选择项或多选项
成功之路
第六课 基本控件
.NET关键词汇-4ຫໍສະໝຸດ CheckBox(复选框)
RadionButton(单选按钮)
RadionButtonList(单选列表)
DropDownList(下拉列表框)
回顾
了解B/S应用程序结构 了解功能 创建虚拟目录 文件结构 界面两大基本控件 Label、Button、TextBox Page_Load事件 事件
DropDownList 控件演示
RadioButtonList 控件演示
总结
使用CheckBox
使用RadioButton
使用RadioButtonList
使用DropDownList