How to bind Choice field Column with DropDownList in SharePoint

There are few steps required to bind Choice field column with dropdownlist.The code is under here:

Guid
siteId = SPContext.Current.Site.ID;
             SPSecurity.RunWithElevatedPrivileges(delegate()
             {
 
                 using (SPSite site = new SPSite(siteId))
                 {
                     using (SPWeb objSPWeb = site.RootWeb)
                     {
SPList objSPList = objSPWeb.Lists["ListName"];
 
SPFieldChoice field = (SPFieldChoice)objSPList.Fields["Column Name"];
                         DropDownList1.DataSource = field.Choices;
                         DropDownList1.DataBind();
                     }
                 }
             });

Ebook Download
View all
Learn
View all