2
Answers

checkbox checked item add another list box c#

Photo of Devendra  Kumar

Devendra Kumar

9y
849
1
i will getting the problem when add to checked item another list box 
 
this is add but it add repeat checked item
 
and this check box inside datalist
 
and the code write on check box OnCheckedChanged events.
 
 
i want checked item add into listbox my code is:
 
 
 
protected void OnCheckedChanged(object sender, EventArgs e)
 {
    foreach (DataListItem item in divProducts.Items)
{
     Label lbl_pro_nm = (Label)item.FindControl("lbl_pro_nm");
     CheckBox chkbox = (CheckBox)item.FindControl("chkbox");
  if (chkbox.Checked)
     {
         ListBox1.Items.Add(lbl_pro_nm.Text);
     }
else
    {
     ListBox1.Items.Remove(lbl_pro_nm.Text);
     }
     }
  }
 

Answers (2)