Search This Blog

Wednesday, December 10, 2014

Bind list items into a dropdown list using c#

Bind list items into a dropdown list using c#

if (!Page.IsPostBack)
                {
                    using (SPSite mySite = new SPSite(SPContext.Current.Web.Url))
                    {
                        using (SPWeb myWeb = mySite.OpenWeb())
                        {
                            SPList list = myWeb.Lists.TryGetList("Employee Info");
                            if (list != null)
                            {
                                SPQuery query = new SPQuery();
                                query.Query = @"<Where><Eq><FieldRef Name='FieldToCompare' LookupId='TRUE'/><Value Type='Integer' ><UserID/></Value></Eq></Where>";
                                query.ViewFields = "<FieldRef Name='Title'/>";
                                query.ViewFieldsOnly = true;
                                SPListItemCollection itemColl = list.GetItems(query);
                                if (itemColl != null)
                                {
                                    EmployeeDD.DataSource = itemColl;
                                    EmployeeDD.DataBind();
                                }
                            }
                        }
                    }

                }

This will help you to bind list items into a dropdown list

No comments:

Post a Comment

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...