Archive

Posts Tagged ‘SPGridView’

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: ,

CheckBox-field sor selecting rows in SPGridView

I also came across this nice article (which is also available here and here by another person) which shows how to add a checkbox to the rows in SPGridView for selecting individual rows.

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.

SPGridView and losing Filtering on Sorting

Ok, seems like I found out where things go wrong about losing filtering when sorting…
I’ve disabled the ViewState for the SPGridView, because when a user refreshes his browser after working with things for a while and just returned from a detailsview of entered the detailsview from the gridview, the error “Failed to load ViewState” appears.
This can be solved by disabling the viewstate for the gridview and/or detailsview (depending on what you want to prevent).
So now I have to find a way to handle this nicely…

Oh, by the way… when I get things sorted out, somewhat, I will post a VS2008 solution with database, so you can see the ‘final thing’…

Categories: SharePoint Tags: , , ,

SPGridView, LinqDataSource and Filtering… and sorting

Ok, so I’ve hit one more snag…
When a filter has been set, and a column is clicked to sort, the filter gets lost.

When an SPGridView sorts, it has an empty FilterFieldName.
So, we have to see if we can store this somewhere.

To be continued…

Working Filtering on SPGridView and Child-properties

Finally, I have my filtering working!! :D

Yesterday while I drove home (about an hours drive), I thought of a different approach to my problem; why not try to handle the stuff while applying the filter. Trick, at least for me, was to figure out how to do this.

Read more…

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.