ASP.NET - problem in dynamically populating checkboxlist
Asked By shah zeb on 30-Dec-11 05:28 AM
i have dynamically populated checkboxlist control on selectedIndexChange of dropdownlist.
Below is the code for that.
The problem is when i re-call i.e., (when the selectedIndexChange of dropdownlist is called again) it appends the newly items with the existing data. i mean if "a" and "b" was the previous result. and on the new selectedIndexchange the result "c" and "d". The checkboxlist shows all four results.
If i do
CbxList.Items.Clear();
then it solves my problem but creates another. i.e., i losses the id on selected Checkboxes.
If i create another checkboxlist. and add it to placeholder.
it also solves the problem but in that case i how can i generate the selectedIndexChange of checkboxlist
Kindly give suggestion...
below is the code
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
loadTracks();
}
///Load Track Function
public void loadTracks()
{
try
{
ConfigurationDB objConfig = new ConfigurationDB();
DataSet ds = objConfig.GetID(Convert.ToInt32(ddl.SelectedValue.ToString()));
// CbxList.Items.Clear();
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
CbxList.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Name"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString()));
}
}
catch(Exception ex)
{
throw ex;
}
}