ASP.NET控件RadioButtonList更改背景色

这是在做预约问题时遇到的。

假如有1~5个号,可以供预约,那么当别人预约某些号码过后,就把预约过的号码改为高亮显示,同时可选性也关闭!

当然具体问题是要结合数据库里数据的,在这里就不再写那么细了。只举个简单的例子。

用的是VS2012。

 

 

前台代码:

<%@ 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 http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:RadioButtonList ID="twhRBL" runat="server" RepeatDirection="Horizontal">
            <asp:ListItem>1</asp:ListItem>
            <asp:ListItem>2</asp:ListItem>
            <asp:ListItem>3</asp:ListItem>
            <asp:ListItem>4</asp:ListItem>
            <asp:ListItem>5</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 _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int[] yiyudingtanweihao = { 0, 1, 0, 1, 1 };//yiyudingtanweihao[0]~yiyudingtanweihao[4]代表摊位号1~5,假如某个被预定了,就把它的值赋为1。
        for (int i = 0; i < 5; i++)
        {
            if (yiyudingtanweihao[i] != 0)//当该摊位号被预定后,就将它背景色显示为红色。同时enabled为false
            {
                twhRBL.Items[i].Text += "已预约";
                twhRBL.Items[i].Enabled = false;
                twhRBL.Items[i].Attributes.Add("style","background-color: red;");
            }
        }
    }

}

 

最终效果:2,4,5已经被预约了。只有1,3能被选中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值