I’m using visual studio 2010 to code my web part.
I have a CheckBoxList which retrieve content from my SharePoint.
SPWeb objCurrentWeb;
SPList objStaffList;
objCurrentWeb = SPContext.Current.Web;
//Using SharePoint object model to retrieve both lists
objStaffList = objCurrentWeb.Lists["Staff List"];
foreach (SPListItem objStaffListItem in objStaffList.Items)
{
staffList.Items.Add(Convert.ToString(objStaffListItem["Name"]));
break;
}
I have another Button on this webpart to retrieve the DateTimeControl. When ever I press the Button, the above list will add duplicate items in my CheckBoxList.
How do I make it such a way that it will not add items into staffList?
In the
protected void Page_Load(object sender, EventArgs e)method useif (!IsPostBack){}and write your check box list populating code inside the brackets.