Sunday, December 4, 2011

Read data from SPFieldChoice and load to DropDownList

The following code enables us to read data from SPFieldChoice and load to DropDownList control


            List<string> listItem = new List<string>();
            SPWeb web = SPContext.Current.Web;
            SPFieldChoice cfStatus = (SPFieldChoice)web.Lists["Employee"].Fields["Position"];
            for (int i = 0; i < cfStatus.Choices.Count; i++)
            {
                string choiceValue = cfStatus.Choices[i].ToString();
                listItem.Add(choiceValue);
            }
            ddl.DataSource = listItem;
            ddl.DataBind();

Hope this helps!

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Affiliate Network Reviews