Home > development, MOSS, MS SharePoint Sever, sharepoint, sps, Uncategorized > Fill Dropdown List with SharePoint List Items

Fill Dropdown List with SharePoint List Items

protected void Page_Load(object sender, EventArgs e)
{
            SPSite mySite = new SPSite(“http://server/sites/site“);
            SPWeb myWeb = mySite.OpenWeb();
            {
                     SPList myList = myWeb.Lists[“ListNameHere”];
                     foreach (SPListItem listRecords in myList.Items)
                    {
                                ListItem tempItem = listRecords[“FieldNameHere”].ToString();
                                ddlFromSPList.Items.Add(tempItem);  //ddlFromSPList is the name of the dropdown list
                    }
           }
}

———————————————————————————————————————————————     
        
private void buildList(DropDownList list, DataSet myDataSet)
{
       foreach(DataColumn dCol in myDataSet.Tables[0].Columns)
      {
             if (dCol.ToString() != “”)
           {
                    ListItem tempItem = new ListItem(dCol.ToString());
                    list.Items.Add(tempItem);
           }
           else
          {
              break;
          }
     }
}

Advertisements
  1. Nav
    May 8, 2009 at 2:16 pm

    this is good.
    but want to show site user in drop down list.
    can help me.

  2. Attiq
    May 19, 2009 at 8:22 pm

    This is helpfull.
    Thanks

  1. January 9, 2010 at 5:36 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: