REPETER嵌套CHECKLIST刷新问题,请热心人帮忙,代码奉上,顶者有分
我点了CHECKBOX后,CHECKBOXLIST中选中的值就被刷掉了,不知道为什么
<asp:repeater id="RepeaterTree" runat="server">
<itemtemplate>
<b>
<asp:CheckBox id="CheckBoxRole" Text='<%# DataBinder.Eval(Container.DataItem,"Popedom_Name") %>' runat="server" AutoPostBack="True" OnCheckedChanged="CheckBoxRole_CheckedChanged">
</asp:CheckBox>
<asp:CheckBoxList id="CheckBoxListUserId" Runat="server" Visible="False"></asp:CheckBoxList>
</b>
<br>
</itemtemplate>
</asp:repeater>
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
this.UpLoadFile.Attributes.Add("onclick","UpLoadFiles();");
string cnnString = @"server=BZ;database=REPETERTREE;uid=sa;pwd=;";
SqlConnection cnn = new SqlConnection(cnnString);
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from C_AccountsPopedom",cnn);
//创建填充 DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds,"C_AccountsPopedom");
RepeaterTree.DataSource = ds.Tables["C_AccountsPopedom"];
RepeaterTree.DataBind();
cnn.Close();
cnn.Dispose();
}
}
public void CheckBoxRole_CheckedChanged(object sender, System.EventArgs e)
{
for(int i=0;i<this.RepeaterTree.Items.Count;i++)
{
CheckBox cb = (CheckBox)RepeaterTree.Items[i].FindControl("CheckBoxRole");
CheckBoxList cbl = (CheckBoxList)RepeaterTree.Items[i].FindControl("CheckBoxListUserId");
string cbText = cb.Text.ToString();
if (cb.Checked==true)
{
string cnnString = @"server=BZ;database=REPETERTREE;uid=sa;pwd=;";
SqlConnection cnn = new SqlConnection(cnnString);
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from Sys_PrsnDossier where ID in(select UserID from Sys_Groups where GroupID = (select Popedom_id from C_AccountsPopedom where Popedom_Name='"+cbText+"'))",cnn);
//创建填充 DataSet.
DataSet ds = new DataSet();
cmd1.Fill(ds,"Sys_PrsnDossier");
//绑定checkboxlist
cbl.DataSource=ds;
cbl.DataTextField="Name";
cbl.DataValueField="ID";
cbl.RepeatColumns=10;
cbl.DataBind();
if(ds.Tables[0].Rows.Count > 0)
{
cbl.Visible=true;
}
}
if (cb.Checked==false)
{
cbl.Visible=false;
}
}
}