?
Solved

SharePoint Column Value on Page

Posted on 2010-11-15
7
Medium Priority
?
549 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
ID: 34140040
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 44

Expert Comment

by:zephyr_hex (Megan)
ID: 34140059
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 44

Expert Comment

by:zephyr_hex (Megan)
ID: 34140065
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:JoMar
ID: 34140304
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 44

Expert Comment

by:zephyr_hex (Megan)
ID: 34140849
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 2000 total points
ID: 34142218
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
ID: 34142231
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Back in July, I blogged about how Microsoft's new server pricing model, combined with the end of the Small Business Server package, would result in significant cost increases for many small businesses (see SBS End of Life: Microsoft Punishes Small B…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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