Sharepoint 2010 Answers

 
Home » Forum » Sharepoint 2010       Ask a questionRSS Feeds
  Question Asked By: Shradha Shrestha   on Aug 13, 2010 In Sharepoint 2010 Category.

 
Question Answered By: Shradha Shrestha   on Aug 13, 2010


0

I have a SPList which has three fields: image  that holds Url of the publishing  image and ImageDescription that holds a single line of text for description and a checkbox field called ImageChecked(yes/NO)

The probelm is if the checkbox is selected, it should display  the image and the ImageDescription on the aspx  page. Ideally there is only one item in the list  with checkbox yes.

I m using SPQuery to query the list.

Here's how I did it. However its not giving me the result I wanted. 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.Lists["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;


}

}
}

Any thoughts on how to achieve this? I am not getting image nor description of image for a checked image. Please help me with this problem.
Thanks.

Tagged:                

 

This Question has 5 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Display Publishing Image to the page from a SPList Or get search suggestion and latest updates.