How do I get values of fields from custom lists?
-
09-12-2019 - |
Frage
I have a custom list ("Contacts") as well as a web part with forms. I want to take the custom list fields and map them to the web part form. My problem is getting the values from the custom list. I've tried looking through both list and field properties but I can't seem to find one that gives the value. I can get everything known to man about the value.
I know it's weird, but I'm just trying to familiarize myself.
protected void Page_Load(object sender, EventArgs e)
{
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Contacts"];
SPListItemCollection listItem = list.Items;
TextCompany.Text = listItem[0].Name;//Returns the list item title
TextFirstName.Text = listItem[0].ToString();//Returns "Microsoft.SharePoint.SPListItem"
}
Lösung
List Item property values are accessed with an indexer. So if you want the value of the "foo" column, then you would write
listItem[0]["foo"]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange