Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

Populate Dropdown with list items

$
0
0

Hi,

I wanted 2 bind list field value to dropdownlist.For that i have used below code in page load.Employee is listname and Ename is the list field name.

if (!Page.IsPostBack)
        {
            using (SPSite site = new SPSite("http://sharepoint-pc:54673/sample/"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPList list = web.Lists["Employee"];
                    DropDownList2.DataSource = list.Items;
                    DropDownList2.DataValueField = "Ename";
                    DropDownList2.DataTextField = "Ename";
                    DropDownList2.DataBind();
                }
            }
        }

bit i got the following exception

DataBinding: 'Microsoft.SharePoint.SPListItem' does not contain a property with the name 'Ename'.  Plz help me where is the problem.Thanks in advance.

regards

Praveen


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>