Monday, March 12, 2007

Create a Dynamic Title in a Data View Web Part Without Code

Well, sort of - this is a bit of a cheat, but the effect is satisfying in cases where users require no control over web parts on a page. All that is required is a little extra XSL. The beauty of this approach is that no web part needs to be written in C# or VB.Net, and that any data available in the data view can be used in the title.

First, set the Chrome Type for the web part to None. Then add a new row to the table in the Data View. The contents of the cell in the row will become the title.

The trick is to apply the standard Web Part title bar CSS styles to the new table. The fragment below shows the styles that need to be applied to the row and to the contents of the cell:

<tr valign="top" class="ms-WPHeader">
    
<td nowrap=""><h3 class="ms-standardheader ms-WPTitle"><span>Matching Suppliers</span></h3></td>
</tr>

No comments: