Solved

SharePoint Column Value on Page

Posted on 2010-11-15
7
537 Views
Last Modified: 2012-05-10
Is there a way to take a value from a given list within a site and have that value displayed on a page without haveing to display the column names or list.  I have a list that defines a project and that list has a title of the project in it.  I want to take that title and have it displayed on the top of the page.  I figure this is simple but not finding it.
0
Comment
Question by:JoMar
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:tstritof
Comment Utility
Hi,

could you please explain your request with more detail? By what criteria should a project be chosen from project list in order to display the title? What data in a page can be used to query the project list?

Regards,
Tomislav
0
 
LVL 42

Expert Comment

by:zephyr_hex
Comment Utility
it's not so simple ;)

by "top of the page", do you mean the browser bar?  or a section of the actual page near the top?

if you mean a section of the page near the top, then you can do this using Sharepoint Designer.

bring up the page in Designer.  put Designer in split code/page view so you can see elements on the page and the code at the same time.  click on the field in the design/page view and it should hop to that section in the code.  that will show you how to reference the field in the top section of your page.

if you want it in the browser title bar, that's a whole 'nother ball of wax...
0
 
LVL 42

Expert Comment

by:zephyr_hex
Comment Utility
sorry... once again i forgot to flip to EE Comment mode.

here we go:
it's not so simple ;)

by "top of the page", do you mean the browser bar?  or a section of the actual page near the top?

if you mean a section of the page near the top, then you can do this using Sharepoint Designer.

bring up the page in Designer.  put Designer in split code/page view so you can see elements on the page and the code at the same time.  click on the field in the design/page view and it should hop to that section in the code.  that will show you how to reference the field in the top section of your page.

if you want it in the browser title bar, that's a whole 'nother ball of wax...
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:JoMar
Comment Utility
I have a site that contains a list that contains a field ("Title") in it.  

I also have a home.aspx page that users go to when they first open the site.  What I want is to take the value from the above list and display it as a header on the home.aspx page.

I am not worried about quering the list as it should only have 1 value in it anyway.  Also, not worried about the browser title.
0
 
LVL 42

Expert Comment

by:zephyr_hex
Comment Utility
displaying that value in the "out of the box" title is going to take coding that is beyond my level of expertise.  i'm sure it can be done.  but not easily.

however, you can likely mimic or get close to the "out of the box" title using other tools.  for these methods, you would modify the code on your main page to add something that looks like the title bar, with the lookup value you want.

here are some methods you could use:
http://www.a2zdotnet.com/View.aspx?id=100

http://msdn.microsoft.com/en-us/library/ee534973.aspx

0
 
LVL 7

Accepted Solution

by:
tstritof earned 500 total points
Comment Utility
Hi,

although I'm not sure I agree with your concept of having a single item WSS list to change the title of the home page I tried to work it out in a little example (just kidding about the concept, I guess you just gave a sandbox example :)).

The screenshots from the example are from my testing site so please disregard the various silly named lists and libraries.

In the first screenshot I displayed a standard (non-customized) WSS home page.
 Standard WSS home page.
The second screenshot shows the contents of a WSS list named "Projects".
 WSS list Projects.
The third screenshot shows the "unpolished" output of customized home page. Since I wasn't sure which location you wanted for your "project title" I embedded it in 2 locations.
 Customized WSS home page.
If this is what you had in mind - read on. If not, please read on anyway - I'll feel better :)

The "solution" has been developed on standard WSS 3.0 installation and is deployed through 2 main steps:
1) Creation and deployment of custom WSS user control named MyPageTitle.ascx.
2) Creation of custom home.aspx page (from default.aspx) that utilizes the new control.

Additionally you'll have to create a list named "Projects" and create at least one item with some title in the list. If you want to name your list differently you can do that but you'll have to modify the ascx accordingly.

If you're using a different version of WSS or MOSS you might run into some problems with deployment. Also MOSS might have some built-in functionality that solves your problem more elegantly but I'm not aware of it (I'm happy playing with WSS - can do less damage).

You'll find both files are attached to this post and here's a little how-to regarding deployment.

The MyPageTitle.ascx file contains:
- the code that queries the list named "Projects" in the current site
- the label that displays the value of "Title" field for the first item it retrieves from the list

To make the control available to WSS pages you'll have to:
- create the "CustomControls" folder in your CONTROLTEMPLATES folder (it's full path is usually "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\CONTROLTEMPLATES")
- copy the MyPageTitle.ascx file to newly created "CustomControls" folder

This deployment should ensure that you don't overwrite any standard WSS user controls (hence the new folder) and prevent any in-line scripting related security problems in WSS since controls deployed to CONTROLTEMPLATES should all be treated as safe by WSS.

The home.aspx can be uploaded to standard WSS 3.0 site document library and tested without any modifications to your WSS site or you can make small customizations to your existing pages (using Sharepoint Designer or other tools). The modifications could also be deployed to master page template but I don't recommend it since this is just a sandbox solution (not tested for stability or much else for that matter).

The first thing to do in the aspx page was to register the new web control. One line has been added to standard default.aspx page code to achieve this (note the path to the ascx):
<%@ Register TagPrefix="mst" TagName="MyPageTitle" src="~/_controltemplates/CustomControls/MyPageTitle.ascx" %>

Open in new window


Both places where title is changed are relying on this new ascx control to do the querying/displaying magic.

However, in order to display the title instead of the site title, the code had to be added to override default content for PlaceHolderSiteName content place holder (which is normally defined in the default.master). That has been achieved by 3 new lines (immediately following the line where web control was registered):
 
<asp:Content ContentPlaceHolderId="PlaceHolderSiteName" runat="server">

	<mst:MyPageTitle ID="MyPageTitle_id1" runat="server"/>

</asp:Content>

Open in new window


And finally a single line of code has been added to target the PlaceHolderPageTitleInTitleArea content place holder (I didn't delete any standard content targeting the same place holder, but you may do that yourself). This is the line (I removed the indent here):
 
<mst:MyPageTitle ID="MyPageTitle_id2" runat="server"/>

Open in new window


And that is it - not much code but not much "bang" either :) The files are here:
 MyPageTitle.ascx
 home.aspx

I was thinking to give you an example of how to solve this by "dirty client side solution" (hidden list web part querying Projects + javascript hidden away in CEWP webpart) without any modification to aspx code but the code and entire solution would be to unstable to actually implement in production environment.

Hope you can make some use of this :).

Regards,
Tomislav
0
 
LVL 7

Expert Comment

by:tstritof
Comment Utility
Sorry for the huge code snippet windows, I have no idea why that happened (looks like too long lines of code are the culprits).

Regards,
Tomislav
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Note:  There are two main ways to deploy InfoPath forms:  Server-side and directly through the SharePoint site.  Deploying a server-side InfoPath form means the form is approved by the Administrator, thus allowing greater functionality in the form. …
SharePoint Designer 2010 has tools and commands to do everything that can be done with web parts in the browser, and then some – except uploading a web part straight into a page that is edited in SPD. So, can it be done? Scenario For a recent pr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now