protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!GetvipTypeCata(CheckBoxList1))
{ }
}
}
/// <summary>
/// 取得会员类型
/// </summary>
/// <param name="DropDownList1"></param>
/// <returns></returns>
public bool GetvipTypeCata(CheckBoxList CheckBoxList1)
{
OleDbDataReader reader = null;
CheckBoxList1.Items.Clear();
string sql = String.Format("SELECT * FROM [option]");
try
{
reader = OleDbHelper.ExecuteReader(Constants.connstring, CommandType.Text, sql);
ListItemCollection item = new ListItemCollection();
while (reader.Read())
{
string strRootID = reader["ID"].ToString();
CheckBoxList1.Items.Add(new ListItem(reader["Name"].ToString(), strRootID.ToString()));
}
CheckBoxList1.DataBind();
}
catch (Exception ex)
{
reader.Close();
return false;
}
reader.Close();
return true;
}
protected void Button1_Click(object sender, EventArgs e)
{
string strrighgs = "";
for (int i = 0; i < this.CheckBoxList1.Items.Count; i++)
{
if (this.CheckBoxList1.Items[i].Selected == true)
{
strrighgs += this.CheckBoxList1.Items[i].Value + "|";
}
}
string str = "";
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
str += li.Value+ ";";
}
}
Label1.Text = str;
}