I got two list boxes when page loads I have to eliminate the items in the first list box if second list box has the same item. Please see the below code. Even I removed it, still shows on the first list box. Please anyone can help me. Thanks. Event: Page_Load // First list box lstUser.DataValueField = "Id"; lstUser.DataTextField = "Name"; lstUser.DataSource = GetUsersByUserType(cp.Department.DepartmentId, UserTypes.Employee); lstUser.DataBind(); //Second list box lstUserAdded.DataValueField = "Id"; lstUserAdded.DataTextField = "Name"; lstUserAdded.DataSource = GetAddedUsers(); lstUserAdded.DataBind(); // Here I am removing the items on the first list box. foreach (ListItem item in lstUserAdded.Items) { lstUser.Items.Remove(item); } //After removing the items on the first list box, the removed items still showing on the first list box when page loads is complete.
we'll need more info. understand, that the contents of the listbox remain within the viewstate even though you wouldn't add the to the list on every post back..