62,254
社区成员
发帖
与我相关
我的任务
分享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;
using System.Data.SqlClient;
using System.Collections;
using System.Text.RegularExpressions;
public partial class _Default : System.Web.UI.Page
{
string CheckBoxList1Item;
string asd;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] str = new string[] ...{ "班级A", "班级B", "班级C", "班级D" };
ListItem items = new ListItem();
for (int i = 0; i < str.Length; i++)
{
CheckBoxList1.Items.Add(items);
}
CheckBoxList1.DataSource = str;
CheckBoxList1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < CheckBoxList1.Items.Count; i++)
{
if (CheckBoxList1.Items[i].Selected)
{
CheckBoxList1Item += ("&"+CheckBoxList1.Items[i].Value);
}
}
Regex r = new Regex("&");
asd = r.Replace(CheckBoxList1Item, "", 1);
//Response.Write(CheckBoxList1Item);
//Response.Write(asd);
string[] ss = Regex.Split(asd,"&");
Response.Write(ss[1]);
}
}