那要看你把你的数据放在什么控件里面吧

解决方案 »

  1.   

    //绑定子类
        protected void dl_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                //绑定子类
                CheckBoxList chk = (CheckBoxList)e.Item.FindControl("chklSub");
                Label lblCountryID = (Label)e.Item.FindControl("lblCountryID");
                string sql = @"select * from T_directory where Parentid = '" + lblCountryID.Text + "' order by DirNameChs";
                DataSet ds = DbHelperSQL.Query(sql);
                chk.DataTextField = "DirNameChs";
                chk.DataValueField = "directoryID";
                chk.DataSource = ds;
                chk.DataBind();
                //确定钩选
                CustomSearchBLL Search = new CustomSearchBLL();
                ds = Search.GetList("UserName='" + UserName + "' and CountryID='" + lblCountryID.Text + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    ((CheckBox)e.Item.FindControl("chklCountry")).Checked = true;
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        foreach (ListItem Check in chk.Items)
                        {
                            if (Check.Value == ds.Tables[0].Rows[i]["SubID"].ToString())
                            {
                                Check.Selected = true;
                            }
                        }
                    }
                }
            }
        }