Posted by Vlad on October 25, 2007

If you try something like this in a GridView or DetailsView you might end up frustrated:
<asp:BoundField DataField=”Percentage” DataFormatString=”{0:f2}%” HeaderText=” Percentage” ReadOnly=”True” SortExpression=”Percentage” />
That’s because no matter what you put in the DataFormatString property, the text is formatted the same way (although the literal characters from outside the brackets do appear, so DataFormatString it’s not completely ignored).
The solution:
<asp:BoundField DataField=”Percentage” DataFormatString=”{0:f2}%” HeaderText=” Percentage” ReadOnly=”True” SortExpression=”Percentage” HtmlEncode=”false” />
Don’t know why…
Posted in .NET, ASP.NET, WCSF | Leave a Comment »
Posted by Vlad on October 16, 2007

As it turns out, if you want to show a non-modal form centered in the boundaries of its parent, in .NET 2.0, you’ll have to set its position manually.
Although the System.Windows.Forms.FormStartPosition.CenterParent works fine if you use form.ShowDialog(owner); (modal form), it doesn’t seem to make a difference when using form.Show (owner); for a non-modal form. I suspect a bug, because I didn’t find any mention of this behavior in help.
The solution:
form.StartPosition = FormStartPosition.Manual;
form.Location = new System.Drawing.Point(form.Owner.Location.X + (form.Owner.Width – form.Width) / 2, form.Owner.Location.Y + (form.Owner.Height – form.Height) / 2);
Posted in .NET, C# | 1 Comment »
Posted by Vlad on October 9, 2007

One annoying thing in SQL 2000 was that you couldn’t select TOP @n records using a variable. The options were to construct the SQL query dynamically or (if you wanted to use stored procedures) to use SET ROWCOUNT @n before the select. And of course not to forget to set it back to 0 as soon as you’re done with it.
SQL 2005 solves this problem. You can now use variables in the TOP count:
CREATE PROCEDURE GetLatestAnnouncements
@topCount int
AS
BEGIN
SELECT TOP (@topCount) * FROM Announcements
ORDER BY DateAdded DESC
END
Another handy addition is the Row_Number() function – it basically gives you the sequential number for a row in a result set. You can use it to get “pages” of records just like those you normally need in a paging DataGrid:
Read the rest of this entry »
Posted in SQL | Leave a Comment »