CheckBoxList clbox = new CheckBoxList();
clbox.Items.Add(new ListItem("text", "value"));
//选中新增加的项
clbox.Items[clbox.Items.Count-1].Selected = true;
ListItem li = new ListItem(); //建立新增ListItem对象
li.Selected = true; //设置为选中状态
CheckBoxList1.Items.Add(li); //添加对象
给你中间的一段核心代码:
_cmd = new SqlCommand("select * from popedom", _con);
try
{
_con.Open();
_dr = _cmd.ExecuteReader();
while (_dr.Read())
{
_tn = new TreeNode();
_tn.Text = _dr["po_Name"].ToString();
_tn.Tag = _dr["po_ID"].ToString();
foreach (popedomEntiInfo var in _list)
{
if (var.Po_ID.ToString().Trim().Equals(_tn.Tag.ToString()))
{
_tn.Checked = true;
}
}
this.treeView1.Nodes[int.Parse(_dr["po_typeID"].ToString())].Nodes.Add(_tn);
}
}