Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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"
    }
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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"]

share|improve this answer
    
Worked like a charm. Thanks for helping out us beginners. –  MiniRagnarok May 25 '12 at 12:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.