这是在做预约问题时遇到的。
假如有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能被选中