I currently am developing a SharePoint Web part that will populate some stuff based of the of the List. Everything is working as expected but I can't seem to access the variable that has all the list items!
The Variable I want to access is theValue1
.
Code:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;
namespace SPListWebPart.VisualWebPart1 {
public partial class VisualWebPart1UserControl : UserControl {
public void Page_Load(object sender, EventArgs e) {
string theValue1;
SPSite site = new SPSite("http://maindt/sites/dev");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Links"];
foreach (SPListItem item in list.Items) {
theValue1 = item["URL"].ToString();
}
}
}
}
theValue1
is a string, not a list, and its value gets overwritten on every iteration of the loop.