Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing SPListitems from a SPList in SharePoint 2010

Status
Not open for further replies.

sspb485

MIS
Aug 13, 2010
1
US
Hi,
I have a SPList in SP 2010. The list has three fields.
Image--- Publishing Image
Image Description---Single line of text
Checked Image--Boolean

I m using SPQuery to retrieve the Image and Image Description on my aspx page for CheckedImage.
How do I do it?
Here's my code but its not giving the result.

I created a usercontrol1.ascx that has
//usercontrol1.ascx.cs has got the code below in page load event.

if (currentWeb != null && currentWeb.Site.RootWeb != null)
{

if (pubPage != null && pubPage.Layout.Title == "Test Home Page Layout")

{

//Get the list
SPList FeaturedImage = currentWeb.List["FeaturedImageDetails"];

//Create a query
SPQuery query = new SPQuery();
query.Query = string.Format("<Where><Eq><FieldRef Name='ImageFeaturedHD' /<Value Type='Boolean'>1</Value></Eq></Where>");


//Get the list items
SPListItemCollection collListItems = FeaturedImage.GetItems(query);
string sUrl = "";
foreach (SPListItem Listitem in collListItems)
{
Microsoft.SharePoint.Publishing.Fields.ImageFieldValue h = (Microsoft.SharePoint.Publishing.Fields.ImageFieldValue)Listitem["Image"];
testImage.ImageUrl = h.ImageUrl;
testLabel.Text = Listitem["ImageDescHD"].ToString();


break;

}


testImage.ImageUrl = sUrl;


}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top