Binding a Databound WebControl to a SharePoint List

To bind a databound WebControl (System.Web.UI.WebControls, etc.), you can use the following code:

DataSet ds = new DataSet();

SPSite myWeb = SPContext.GetContext(HttpContext.Current).Web;

SPList list = myWeb.Lists["ListName"];
DataTable DTable_List = list.Items.GetDataTable();
DTable_List.TableName = "Table1";
ds.Tables.Add(DTable_List);

DropDownBGroup.DataSource = ds.Tables["Table1"];
DropDownBGroup.DataTextField = "FieldName";
DropDownBGroup.DataValueField = "FieldName";
DropDownBGroup.DataBind();
DropDownBGroup.SelectedIndex = 0;

myWeb.Dispose();
Bookmark and Share
Leave a comment

0 Comments.

Leave a Reply


[ Ctrl + Enter ]

Performance Optimization WordPress Plugins by W3 EDGE