문제

I have a SharePoint list that contain column 'District' with some data in it. It contains 4 value, District 1, District 2, District 3 and District 4.

I want to grab that value 'District' in the SharePoint list items and put it in my ASP Form as a checkbox to eventually make a filter on a Grid View.

If anyone can help me with grabbing the value of SharePoint List items and turning it into checkbox, would really appreciate it.

도움이 되었습니까?

해결책

In case, the District is a single line of text, try the below code

using (SPSite site = new SPSite("SiteURL"))
   {
     using (SPWeb web = site.OpenWeb())
      {
       SPList list = web.Lists["ListName"];
       SPQuery query = new SPQuery();
       query.Query = "<View><ViewFields><FieldRef Name='District'/></ViewFields></View>"; 
       SPListItemCollection Items = list.GetItems(query);
      // Bind Checkbox List
       foreach (SPListItem Item in Items)
          {
             //CheckBoxListID.Items.Add(item["District"]);
              CheckBoxListID.Items.Add(new ListItem(Item.Title));
          }
      }
}

In case, the District is your field is a choice field, Please check, Retrieve a SharePoint Choice Field Value Using Server Object Model C#

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top