Archive

Posts Tagged ‘WebPart’

SPGridView and Right-aligning Header-text

SPGridView is a really nice control. One of the problems I have encountered with it, is that when you set a column to show its header-text right-aligned, you can wait all you want, it will not happen.

Did some more searching in the internet today, and found a solution I based my final implementation on.

First, create a private generic List if integers for the application :

List<int> rightAlignCellsGridView = new List<int>() { };

Now, create the columns and set <code>HeaderStyle.HorizontalAlign</code> to <code>HorizontalAlign.Right</code> for the columns where you want the headertext right-aligned.

Next, after adding the SPGridView to the controls-collection, use the following:

foreach (DataControlField col in this.gridView.Columns.OfType<DataControlField>().Where(c =>
    c.HeaderStyle.HorizontalAlign == HorizontalAlign.Right && c.Visible == true))
 {
    this.rightAlignColGridView.Add(this.gridView.Columns.IndexOf(col));
 }

Next, add an event to the SPGridView’s RowDataBound-event and add the following code there:

switch (e.Row.RowType)
 {
   case DataControlRowType.Header:
     foreach (int idx in rightAlignColGridView)
     {
       e.Row.Cells[idx].Style.Add("text-align", "right");
     }
     break;
   default:
     break;
 }

Now, compile and watch the results…

Categories: C#, SharePoint Tags: , ,

Adding ‘formatted’ fields to a SPGridView

While updating the WebPart of my main-project at work, I wanted to find a way to not use BoundField, but still be able to format how my data is displayed.

Then, I ran into this link.

Categories: SharePoint Tags: ,

I just came across a nice addition to my base web part:

if (Microsoft.SharePoint.SPContext.Current.FormContext.FormMode == SPControlMode.Display)
{
   // your code to support display mode
}
else // Microsoft.SharePoint.SPContext.Current.FormContext.FormMode = SPControlMode.Edit
{
   // your code to support edit mode
}

Since it isn’t mine, credits go to this post.

Categories: C#, SharePoint Tags: ,

Solution File and DataBase for SPGridView with working Filtering, Sorting, etc.

I finally managed to create a solution with all the bells whistling and sort… as far as I know.

The Visual Studio 2008 solution can de found here.
The SQL database can be found here.
Attach the database in SQL. If you find any problems or have any questions, please leave a comment or send me a mail.

For this solution to work, you need to have added the AJAX-entries to the web.config of your MOSS2007 with SP1 installation, as well as the infrastructure-update.
Compile and add the compiled DLL’s to the BIN-directory of your site. By default, the Debug-version automatically gets compiled to the path “C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin”.
Then, add the correct entries in web.config (SafeControls and Assemblies), then, add the WebParts (DevTinkeringParents en DevTinkeringChilds) to the WebPart-gallery and put them in a WebPart-zone on a page of your liking. ;)

You also need to have Visual Studio enhancements for WSS 1.3 installed, because the WebParts are based on the SharePoint WebPart-template.

Update…

Currently I’m trying to put together the VS2008 Solution containing the stuff I’ve written about the last few weeks.
That is… I’m now installing SP2 on my Windows 2008 Virtual Machine, which seems to take forever.
Hopefully I can continue work on the solution tomorrow.

Using Embedded resources in an ASPX-page/WebPart

I’m implementing UpdatePanel and UpdateProgress into my (Base)WebPart and since it is nice to have a ‘while processing’-image, I thought about embedding it as a resource.

This link helped me to accomplish this.

This post helped me to embed the required CSS and JavaScript directly into the page.
4GuysFromRolla have a very nice article here where I got the ‘modal updateprogress’ from I now use.

And again, when I get somewhere near to a complete thing, I’ll post a sample-solution with all this stuff in it.

UpdatePanel-usage in SharePoint SP1+ WebParts

Yeah, I know… I promised to deliver some source-code…. Still working on the stuff, though

I’m trying to AJAX-ify the WebPart. Since Service Pack 1 both WSS3 and MOSS2007 have AJAX-support. So, I thought I would add an UpdatePanel-control to my WebPart and make things happen. However, there still needs to be some configuration done in the web.config. I ran into a very very helpful link here.
Omit the lines with “AJAXControlKit”. These are not needed, and in fact generate errors. Unless you have the AJAX Control Kit installed… Which you do not need for UpdatePanel to work…

This link helped me too, in preventing a full postback…

This link provides some more info on UpdatePanels and UpdateProgress and sorts… also really useful.

SPGridView, Sorting, Filtering, Linq… WebParts…….

I came across some very nice articles when browsing the internet for some information on how to enable filtering and sorting an an SPGridView with a LinqDataSource as datasource. The most usefull one I found is this one from Johan Leino.

However, there are still some things to be done. Read more…

Follow

Get every new post delivered to your Inbox.