欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP.NET中 RadioButtonList 单选按钮组控件的使用方法

程序员文章站 2023-12-15 17:38:52
radiobuttonlist 控件表示一个封装了一组单选按钮控件的列表控件。 可以使用两种类型的 asp.net 控件将单选按钮添加到网页上:各个 radiobutto...

radiobuttonlist 控件表示一个封装了一组单选按钮控件的列表控件。

可以使用两种类型的 asp.net 控件将单选按钮添加到网页上:各个 radiobutton 控件或一个 radiobuttonlist 控件。这两类控件都允许用户从一小组互相排斥的预定义选项中进行选择。使用这些控件,可定义任意数目的带标签的单选按钮,并将它们水平或垂直排列。

一、常用属性

属性 作用
repeatdirection horizontal|vertical 项的布局方向:水平方向|竖直风向
repeatlayout table|flow 展现方式:表格|流线型
selected true|falsee 是否为选中状态

二、代码演示

前台 radiobuttonlist.aspx

复制代码 代码如下:

<%@ page language="c#" autoeventwireup="true" codefile="radiobuttonlist.aspx.cs" inherits="webcontrols_radiobuttonlist" %>
 
<!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>
        <h3>radiobuttonlist(单选按钮组)</h3>
        <hr />
        请选择性别:<asp:radiobuttonlist
            id="radlsex" runat="server" repeatdirection="horizontal" repeatlayout="flow">
            <asp:listitem selected="true">男</asp:listitem>
            <asp:listitem>女</asp:listitem>
        </asp:radiobuttonlist>
        <br />
        <asp:button id="btnsubmit" runat="server" text="提交" onclick="btnsubmit_click" />
        <hr />
        你选择的性别为:<asp:label id="lblstate" runat="server"></asp:label>
      
    </div>
    </form>
</body>
</html>

后台 radiobuttonlist.aspx.cs

复制代码 代码如下:

using system;
using system.collections.generic;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
 
public partial class webcontrols_radiobuttonlist : system.web.ui.page
{
    protected void page_load(object sender, eventargs e)
    {
 
    }
    protected void btnsubmit_click(object sender, eventargs e)
    {
        lblstate.text = radlsex.selectedvalue;
    }
}

上一篇:

下一篇: