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
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