0

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
}

1 Answer 1

3

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();          
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.