Binding a Databound WebControl to a SharePoint List
by liquidpooled on Jul.22, 2008, under .NET, Microsoft, Office, Sharepoint Server, Visual Studio 2005, Visual Studio 2008, Windows SharePoint Services
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();
No comments for this entry yet...