简体   繁体   中英

CheckBoxList not updated - ASP.Net

I have a checkbox list that get its data from DB. User will select/check boxes and click delete. After the delete, I'm rebinding the new data, but the changes aren't reflected. The page still shows those selected checkboxes. The records are deleted in DB though. am i missing something.

ASPX:

<asp:CheckBoxList ID="cblLanguages" runat="server" AppendDataBoundItems="true" 
            DataTextField="LanguageName" DataValueField="PKLanguageId" >            
</asp:CheckBoxList>
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="Delete" />

C#:

protected void Page_Load(object sender, EventArgs e)
    {
        if(!Page.IsPostBack)
        {
            BindData();
        }
    }

protected void btnDelete_Click(object sender, EventArgs e)
    {
       DeleteLanguages();
       BindData();
    }

private void BindData()
{
    DataSet dsData = LanguagesDB.GetLanguages();
    cblLanguages.DataSource = dsData.Tables[0];
    cblLanguages.DataBind();          
}
private void DeleteLanguages()
{
   //code to delete selected values
}

Every time loading the CheckboxList clear the items and Load.

private void BindData()
{
    if(cblLanguages.Items.Count > 0)
       cblLanguages.Items.Clear();
    DataSet dsData = LanguagesDB.GetLanguages();
    cblLanguages.DataSource = dsData.Tables[0];
    cblLanguages.DataBind();          
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM