【发布时间】:2011-04-18 20:57:12
【问题描述】:
我有 5 个复选框列表,每个复选框列表都有相同的 6 个复选框。
在某些条件下,我必须在page_Load 期间检查这些复选框列表。
我该怎么做?
for (int j = 0; j < no_of_listitem; j++)
{
SqlCommand check = new SqlCommand("SELECT ISGoal1, ISGoal2,ISGoal3, ISGoal4,ISGoal5 FROM PRM2011_EMPLOYEE_GOAL WHERE EmployeeID = '" + employeeid[j] + "'", con);
SqlDataReader y = check.ExecuteReader();
while (y.Read())
{
if (null != y && y.HasRows)
{
string yes_or_no = y["ISGoal1"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList1.Items[j].Selected = true;
}
//else CheckBoxList1.Items[j].Selected = false;
yes_or_no = y["ISGoal2"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList2.Items[j].Selected = true;
}
//else CheckBoxList2.Items[j].Selected = false;
yes_or_no = y["ISGoal3"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList3.Items[j].Selected = true;
}
//else CheckBoxList3.Items[j].Selected = false;
yes_or_no = y["ISGoal4"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList4.Items[j].Selected = true;
}
//else CheckBoxList4.Items[j].Selected = false;
yes_or_no = y["ISGoal5"].ToString();
yes_or_no = yes_or_no.Trim();
if (yes_or_no == "Yes")
{
CheckBoxList5.Items[j].Selected = true;
}
//else CheckBoxList5.Items[j].Selected = false;
}
}
y.Close();
}
employeeid[] 包含 6 个员工的 id。no_of_listitems 是 6,这是这 6 个员工 id 的列表。
【问题讨论】:
标签: asp.net checkbox checkboxlist