Devendra  Kumar

Devendra Kumar

  • NA
  • 517
  • 233.8k

checkbox checked item add another list box c#

Jul 28 2016 1:13 AM
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)