Hello,
Requirement :
1. Create a visual Webpart which has a dropdown box , a button and a label :
2. Data should be fetched from a list in the same site and populated in the dropdown box .
3. When a item is selected from dropdown box and clicked on the button , some data should be showing in the Label.
Issue:
I am writing the below simple code to fetch data from a list. I am getting the red squiggles as error on oSPSite andlist.GetItems(). I have added all the required namespaces and yet my SPSite object (oSPSite) is not getting recognized. Please let me know if I am missing some important namespace. PFB code and screentshot(if visible) :
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.CSharp;
namespace AcronymSP.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public partial class VisualWebPart1 : WebPart
{
// Uncomment the following SecurityPermission attribute only when doing Performance Profiling on a farm solution
// using the Instrumentation method, and then remove the SecurityPermission attribute when the code is ready
// for production. Because the SecurityPermission attribute bypasses the security check for callers of
// your constructor, it's not recommended for production purposes.
// [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Assert, UnmanagedCode = true)]
public VisualWebPart1()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
using (SPSite oSPSite = new SPSite("http://........"))
{
using (SPWeb oSPWeb = newoSPSite.OpenWeb())
{
SPList list = oSPWeb.Lists["AcronymsList"];
SPListItem item =list.GetItems();
}
}
}
}
}
Thanks in advance,
Guru