为什么我循环datatable,得到的总是第一列的值。
DataTabledt1=AdminUserManager.GetDataTableAllAdminUser();if(dt1!=null&&dt1.Rows.Count...
DataTable dt1 = AdminUserManager.GetDataTableAllAdminUser();
if (dt1 != null && dt1.Rows.Count > 0)
{
foreach (DataRow dr in dt1.Rows)
{
strtemp = dr["AdminLimitId"].ToString();
for (int i = 0; i < ((CheckBoxList)e.Item.FindControl("CheckBoxList1")).Items.Count; i++)
{
CheckBoxList cb1 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
if (strtemp.Contains(cb1.Items[i].Value))
{
CheckBoxList cb2 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
cb2.Items[i].Selected = true;
}
}
}
} 展开
if (dt1 != null && dt1.Rows.Count > 0)
{
foreach (DataRow dr in dt1.Rows)
{
strtemp = dr["AdminLimitId"].ToString();
for (int i = 0; i < ((CheckBoxList)e.Item.FindControl("CheckBoxList1")).Items.Count; i++)
{
CheckBoxList cb1 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
if (strtemp.Contains(cb1.Items[i].Value))
{
CheckBoxList cb2 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
cb2.Items[i].Selected = true;
}
}
}
} 展开
展开全部
按你的意思应该是先把数据放到一个字符串里面去才可以,你的这个得道的不是第一个,而是最后一个,每次都把数据放到了里面就重新赋值了
foreach (DataRow dr in dt1.Rows)
{
strtemp+ = dr["AdminLimitId"].ToString();
}
for (int i = 0; i < ((CheckBoxList)e.Item.FindControl("CheckBoxList1")).Items.Count; i++)
{
CheckBoxList cb1 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
if (strtemp.Contains(cb1.Items[i].Value))
{
CheckBoxList cb2 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
cb2.Items[i].Selected = true;
}
}
foreach (DataRow dr in dt1.Rows)
{
strtemp+ = dr["AdminLimitId"].ToString();
}
for (int i = 0; i < ((CheckBoxList)e.Item.FindControl("CheckBoxList1")).Items.Count; i++)
{
CheckBoxList cb1 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
if (strtemp.Contains(cb1.Items[i].Value))
{
CheckBoxList cb2 = (CheckBoxList)e.Item.FindControl("CheckBoxList1");
cb2.Items[i].Selected = true;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询