Pages - Menu

Kentico Prev Next navigation thru document

Just a quick dirt hack to get prev next working with a repeater webpart.


Under transformation we will do this. (This particular case use the Blog document type)

   1: <p class="linked" <%# (Eval("DocumentNodeID").ToString() == CMSContext.CurrentDocument.GetValue("DocumentNodeID").ToString()) ? string.Empty : "style='display:none;'"%>>

   2:     <span class="prev"> <a href="<%# (DataItemIndex >= DataRowView.DataView.Count - 1) ? string.Empty : DataRowView.DataView[DataItemIndex + 1]["NodeAliasPath"].ToString() %>" rel="prev"> 

   3:     <%# (DataItemIndex >= DataRowView.DataView.Count - 1) ? string.Empty : "&laquo; " + DataRowView.DataView[DataItemIndex + 1]["BlogPostTitle"].ToString() %> </a> </span>


   5:     <span class="next"> <a href="<%# (DataItemIndex <= 0) ? string.Empty : DataRowView.DataView[DataItemIndex - 1]["NodeAliasPath"].ToString() %>" rel="next"> 

   6:     <%# (DataItemIndex <= 0) ? string.Empty : DataRowView.DataView[DataItemIndex - 1]["BlogPostTitle"].ToString() + " &raquo;" %> </a></span>

   7: </p>

And look something like this.

Get non modern ui adobe reader without download manager

It was quite an annoying thing to have full screen modern ui adobe reader in Windows 8. Regular download link would yield to the Adobe download manager. Solution?

The following should be bookmarked!!

Calculate age in .Net


I wanted to calculate a person's age in .Net. I am a little disappointed there is no SQL-like DateDiff function in .Net Framework.
If you search on Google, you will find these with high rank and votes.
I didn't like the idea of converting dates to float back and forth so that you can add milliseconds to the date or trying to divide the date by 365.242199 so that we are catering leap years that occur every 4 years but not the 100th but then the 400th year again and so on….


If someone ask me how old am I, it is simple logical process.
  • What year am I in? 
  • What year did I born? 
  • And have I had my birthday this year yet?
With this in mind, the pseudocode is simple. If I didn’t pass my birthday, then my age is calculated by this year but take out 1.

public int? Age
        return (DateTime.Today.DayOfYear >= DOB.DayOfYear)
                    ? (DateTime.Today.Year - DOB.Year)
                    : (DateTime.Today.Year - DOB.Year - 1);

The SMART rule of KPI

KPI - Key Performance Index needs to comply to the following SMART rules:-

  • Specific
  • Measureable
  • Achievable
  • Relevant
  • Time-bounded
KPI should contain 2 - 4 conceptual items over a period of time, then break it down further to include quality and quantity or other quantifiers.
The following illustrate as an example.

Blog Writer


I use Windows Live Writer

And I use this plugin to highlight source code


Surely there are better ways out there and this is subject to improve, but at least this is what I use at the moment.

Visual Studio Styles that visually works for MVC

When we talk about visual studio styles, I think everyone would have downloaded and used son-of-obsidian before. Me too, but once I started working with MVC, this popular style seems to have a drawback when highlighting text in the view (.cshtml). I have tried a few and finally settle with this.

The highlighted color is actually distinctive from the background. Give it a try if you were stuck with highlight / background color just like me.

How to get the Sum of all column values in the last row of a resultset?


As illustrated, ever wonder how to get the sum of column values into the last row as part of the resultset?

Wouldn’t it be nice to let SQL layer to handle all the aggregations and just bind the whole datasource to a .Net control and display as is?


Let’s see how it was done.


To demonstrate, I have added 2 extra columns to the result set


This was achieved by using GROUPING and ROLLUP (will talk about it at the end).


As you can see, GROUPING indicated in the resultset as if the columns were calculated by the SQL Server and is not part of the normal aggregation result set.

As you may now wonder, if I group another column, it will show as 1 too, because that is the total of everything.


This is the final code of how things were done.

Pay attention to on how ROLLUP is applied to the GROUP BY. Combining HAVING and GROUPING, you will then get the desired sub total or grand total of the column values.

select QuestionId
     , QuestionType
     , QuestionNumber, ISNULL(QuestionDesc, 'Total') as QuestionDesc
     , Question, SUM([Weight]) as [Weight]
     , Grouping(QuestionId) AS GroupingQuestionId
     , Grouping(QuestionType) AS GroupingQuestionType
from (

    -- snipped

) Derived
group by rollup(QuestionId, QuestionNumber, QuestionDesc, Question, [Weight], QuestionType)
having Grouping(QuestionType) = 0 or (Grouping(QuestionId) = 1 and Grouping(QuestionType) = 1 and .........)


This is a very advanced topic, and my originally query calculates 4 subtotals and 1 grand total. Hence the need of using derived table. If you are only calculating subtotals / totals from 1 table, then you will not use derived table. It was a little difficult to hide the business knowledge versus demonstrating on how to do it, but this select from where group by rollup having grouping will definitely get you a good start.