阿赛·游梦鱼·郭言赛·阿赛工作室
技术分类
推荐技术
近期热门技术

radiobutton

  •  字体:
  • 代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="radiobutton.aspx.cs" Inherits="radiobutton" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:RadioButton ID="rbRight" runat="server" GroupName="checkanswer" Text="正确" AutoPostBack="true"
                    oncheckedchanged="rbRight_CheckedChanged" /><br />
                <asp:RadioButton ID="rbWrong" runat="server" GroupName="checkanswer" Text="错误" AutoPostBack="true"
                    oncheckedchanged="rbRight_CheckedChanged" /><br />
                <asp:Label ID="lbanswer" runat="server"></asp:Label>
                请从下面选择您最喜欢的一种颜色:<br />
                <asp:Label ID="lbLike" runat="server" Text="黄色"></asp:Label>
                <asp:RadioButtonList ID="rbColorList" runat="server"
                    autopostback="true" RepeatColumns="10" RepeatDirection="Horizontal"
                    OnSelectedIndexChanged="rbColor_Selected">
                    <asp:ListItem Value="黄色" Selected="True">黄色</asp:ListItem>
                    <asp:ListItem Value="绿色">绿色</asp:ListItem>
                    <asp:ListItem Value="红色">红色</asp:ListItem>
                    <asp:ListItem Value="黑色">黑色</asp:ListItem>
                    <asp:ListItem Value="紫色">紫色</asp:ListItem>
                    <asp:ListItem Value="蓝色">蓝色</asp:ListItem>
                </asp:RadioButtonList>
            </div>
        </form>
    </body>
    </html>



    代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class radiobutton : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void rbRight_CheckedChanged(object sender,EventArgs e)
        {
            if (rbRight.Checked)
                { lbanswer.Text = "对不起!您答错了!正确答案应该是:错误。";
                    lbanswer.ForeColor = System.Drawing.Color.White;
                    lbanswer.BackColor = System.Drawing.Color.Red;
                }
                else if(rbWrong.Checked)
            {
                lbanswer.Text = "恭喜您,答对了!;";
                    lbanswer.ForeColor = System.Drawing.Color.White;
                    lbanswer.BackColor = System.Drawing.Color.Green;
                }
                }
        protected void rbColor_Selected (object sender,EventArgs e)
        {
            int totalcount = rbColorList.Items.Count;
            for (int i=0;i<totalcount;i++)
            {
                if(rbColorList.Items[i].Selected)
                {
                    lbLike.Text = rbColorList.SelectedValue;
                    lbLike.ForeColor = System.Drawing.Color.Red;
                }
            }
        }
    }
    Powered by eesai.Com ©  2017  阿赛工作室 All Rights Reserved
    本网站由 阿赛工作室 提供源代码技术支持.  备案号:苏ICP备08114364号

    网站地图建议反馈MapRssXml回到顶部