Thursday, March 31, 2011

SQL ... Select all rows after skipping rows count

I need to select all rows after skipping rows count and here is the select statement for that :

SELECT TOP(@COUNT)
[UserId]
,[LinkId]
,[ShareDate]
,[SharedFromUserId]
,[TotalLike]
,[TotalDislike]
FROM
(
SELECT [t0].*, ROW_NUMBER() OVER (ORDER BY [t0].ShareDate DESC) as RowIndex
FROM UserLink AS [t0]
WHERE [t0].UserId IN ((SELECT UserId FROM UserReader WHERE ReaderId = @USERID) UNION (SELECT @USERID))
) AS [t1]
WHERE [t1].RowIndex > @SKIP
ORDER BY [t1].RowIndex

Using LINQ, You can do it with SKIP and TAKE methods which are another solution. But in my case it was not a good idea to do that as it was a part of a long procedure :)

Hope it helps ...

Wednesday, March 23, 2011

Text Truncate with three dots

Most of the time I work with this via extension methods and display only number of characters of a string then adding 3 dots ...

On current project I need to display a text not limited by number of characters but by a specified width ...

I did it by applying a style on div as you see below:

<div style="overflow:hidden; text-overflow:ellipsis;white-space:nowrap">
<asp:Label ID="lblTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</div>

If you need to do it programatically you can see this link, but I did not try it :

Hope it helps you all,
Inform me if you find any problem or a better way