ASP.NET中 RadioButtonList 選項按鈕組控制項的使用方法_基礎應用

來源:互聯網
上載者:User

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;
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.