先看代码:ASP.NET:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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>
您的兴趣爱好:<asp:Label ID="Label1" runat="server" Text="Label" Width="306px"></asp:Label><br />
<br />
<br />
<asp:CheckBoxList ID="CheckBoxList1" runat="server" Width="80px">
<asp:ListItem>钓鱼</asp:ListItem>
<asp:ListItem>养花</asp:ListItem>
<asp:ListItem>读书</asp:ListItem>
<asp:ListItem>运动</asp:ListItem>
</asp:CheckBoxList><br />
<br />
<asp:CheckBox ID="CheckBox1" runat="server" Text="是否允许别人看到" OnCheckedChanged="CheckBox1_CheckedChanged" />
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="提交" /></div>
</form>
</body>
</html>
C#:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
Label1.Text = "";
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (ListItem Item in CheckBoxList1.Items)
{
Label1.Text = "";
if (Item.Selected)
Label1.Text = Label1.Text +","+Item.Value.ToString();
}
}
}
我想弄成点击了checkbox后,label1.text输出的不显示,但是上面这样写后,不管选不现checkbox,label1都不显示了··无语,望高手解答