Add SharePoint list choice field data to dropdown
SPSite oSite = new SPSite(url);
SPWeb myWeb = oSite.OpenWeb();
SPFieldChoice myField = (SPFieldChoice)myWeb.Lists["List Name"].Fields["FieldName"];
DataTable dataTasks = new DataTable();
DataColumn[] dtCols = new DataColumn[] { new DataColumn("FieldName", Type.GetType("System.String")) };
dataTasks.Columns.AddRange(dtCols);
for (int i = 0; i < myField.Choices.Count; i++)
{
DataRow dRow = dataTasks.NewRow();
dataTasks.Rows.Add(Convert.ToString(myField.Choices[i]));
}
this.DrpTask.DataSource = dataTasks;
this.DrpTask.DataValueField = Convert.ToString(dataTasks.Columns["FieldName"]);
this.DrpTask.DataTextField = Convert.ToString(dataTasks.Columns["FieldName"]);
this.DrpTask.DataBind();
this.DrpTask.Items.Insert(0, "All");
SPSite oSite = new SPSite(url);
SPWeb myWeb = oSite.OpenWeb();
SPFieldChoice myField = (SPFieldChoice)myWeb.Lists["List Name"].Fields["FieldName"];
DataTable dataTasks = new DataTable();
DataColumn[] dtCols = new DataColumn[] { new DataColumn("FieldName", Type.GetType("System.String")) };
dataTasks.Columns.AddRange(dtCols);
for (int i = 0; i < myField.Choices.Count; i++)
{
DataRow dRow = dataTasks.NewRow();
dataTasks.Rows.Add(Convert.ToString(myField.Choices[i]));
}
this.DrpTask.DataSource = dataTasks;
this.DrpTask.DataValueField = Convert.ToString(dataTasks.Columns["FieldName"]);
this.DrpTask.DataTextField = Convert.ToString(dataTasks.Columns["FieldName"]);
this.DrpTask.DataBind();
this.DrpTask.Items.Insert(0, "All");
No comments:
Post a Comment