Some time we need to bind some column of SharePoint list to one Drop-Down.
When i had started working on SharePoint i used to bind Drop-Down with list through For Each loop, so it was time consuming and not good in programming.
Now i use simple and easy code without any loop.
Dim ds As New DataSet()
Dim mySite As SPSite = SPContext.Current.Site
Dim myWeb As SPWeb = mySite.OpenWeb()
Dim list As SPList = myWeb.Lists("ListName")
Dim DTable_List As DataTable = 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
I hope this will helpful for you,
Thanks and Regards
No comments:
Post a Comment