<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Flixon.com</title>
	<link>http://www.flixon.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Tue, 24 Jun 2008 17:56:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.1</generator>
	<language>en</language>
			<item>
		<title>Wizard Control Enter Submit Fix</title>
		<link>http://www.flixon.com/2008/05/01/wizard-control-enter-submit-fix/</link>
		<comments>http://www.flixon.com/2008/05/01/wizard-control-enter-submit-fix/#comments</comments>
		<pubDate>Thu, 01 May 2008 11:32:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2008/05/01/wizard-control-enter-submit-fix/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2008/05/01/wizard-control-enter-submit-fix/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Custom ASP.NET Data Pager Control</title>
		<link>http://www.flixon.com/2008/04/28/custom-aspnet-data-pager-control/</link>
		<comments>http://www.flixon.com/2008/04/28/custom-aspnet-data-pager-control/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 13:51:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2008/04/28/custom-aspnet-data-pager-control/</guid>
		<description><![CDATA[Hi, i like many others have been frustrated by the limitations of the DataPager control introducted in v3.5 of the .NET framework.  The main problem is that it is tied in with the DataSource controls.  Whilst i did manage to come up with a solution using the OnPagePropertiesChanging event of the ListView i still couldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, i like many others have been frustrated by the limitations of the DataPager control introducted in v3.5 of the .NET framework.  The main problem is that it is tied in with the DataSource controls.  Whilst i did manage to come up with a solution using the OnPagePropertiesChanging event of the ListView i still couldn&#8217;t find a solution to display my pager without using LINQ to SQL or without the Object/Linq DataSource control or without setting the DataSource to the entire record set which is very inefficient.  Therefore I set about coming up with my own solution and have come up with:</p>
<p><code>namespace Flixon.Web.UI.WebControls<br />
{<br />
public class PagerCommandEventArgs : CommandEventArgs<br />
{<br />
public int StartRowIndex { get; set; }<br />
public int MaximumRows { get; set; }</code><code>public PagerCommandEventArgs(int startRowIndex, int maximumRows, CommandEventArgs originalArgs) : base(originalArgs)<br />
{<br />
this.StartRowIndex = startRowIndex;<br />
this.MaximumRows = maximumRows;<br />
}<br />
}</code><code>public class Pager : WebControl, INamingContainer<br />
{<br />
public new int Page<br />
{<br />
get<br />
{<br />
if (!string.IsNullOrEmpty(HttpContext.Current.Request.QueryString[this.QueryStringField]))<br />
return Convert.ToInt32(HttpContext.Current.Request.QueryString[this.QueryStringField]);<br />
else<br />
return (int)(this.ViewState["Page"] ?? 1);<br />
}<br />
set { this.ViewState["Page"] = value; }<br />
}</code><code>public int PageSize<br />
{<br />
get { return (int)(this.ViewState["PageSize"] ?? 15); }<br />
set { this.ViewState["PageSize"] = value; }<br />
}</code><code>public int TotalRowCount<br />
{<br />
get { return (int)(this.ViewState["TotalRowCount"] ?? 0); }<br />
set { this.ViewState["TotalRowCount"] = value; }<br />
}</code><code>public int StartRowIndex<br />
{<br />
get { return (this.Page - 1) * this.PageSize; }<br />
}</code><code>public int TotalPageCount<br />
{<br />
get { return (int)Math.Ceiling((double)this.TotalRowCount / (double)this.PageSize); }<br />
}</code><code>public string Url<br />
{<br />
get { return (string)(this.ViewState["Url"] ?? string.Empty); }<br />
set { this.ViewState["Url"] = value; }<br />
}</code><code>public string QueryStringField<br />
{<br />
get { return (string)(this.ViewState["QueryStringField"] ?? string.Empty); }<br />
set { this.ViewState["QueryStringField"] = value; }<br />
}</code><code>public bool ShowPreviousNextLinks<br />
{<br />
get { return (bool)(this.ViewState["ShowPreviousNextLinks"] ?? true); }<br />
set { this.ViewState["ShowPreviousNextLinks"] = value; }<br />
}</code><code>private static readonly object EventPagerCommand = new object();<br />
public event EventHandler&lt;PagerCommandEventArgs&gt; PagerCommand<br />
{<br />
add<br />
{<br />
this.Events.AddHandler(EventPagerCommand, value);<br />
}<br />
remove<br />
{<br />
this.Events.RemoveHandler(EventPagerCommand, value);<br />
}<br />
}</code><code>protected void OnPagerCommand(PagerCommandEventArgs e)<br />
{<br />
EventHandler&lt;PagerCommandEventArgs&gt; handler = (EventHandler&lt;PagerCommandEventArgs&gt;)base.Events[EventPagerCommand];</code><code>if (handler != null)<br />
handler(this, e);<br />
}</code><code>protected override void CreateChildControls()<br />
{<br />
if (!string.IsNullOrEmpty(this.QueryStringField))<br />
this.CreatePageForQueryString();<br />
else<br />
this.CreatePagerForCommand();<br />
}</code><code>private void CreatePageForQueryString()<br />
{<br />
if (this.TotalRowCount &gt; this.PageSize)<br />
this.Controls.Add(new LiteralControl("Page:"));</code><code>// Add the previous links<br />
if (this.Page &gt; 1 &amp;&amp; this.ShowPreviousNextLinks)<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateLink("«", 1));<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateLink("‹", this.Page - 1));<br />
}</code><code>// Loop through the pages<br />
if (this.TotalRowCount &gt; this.PageSize)<br />
{<br />
for (int i = (this.Page &lt;= 2 ? 1 : this.Page - 2); i &lt;= (this.Page &gt;= this.TotalPageCount - 2 ? this.TotalPageCount : this.Page + 2); i++)<br />
{<br />
if (this.Page == i)<br />
this.Controls.Add(new LiteralControl(" &lt;u&gt;" + i.ToString() + "&lt;/u&gt;"));<br />
else<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateLink(i.ToString(), i));<br />
}<br />
}</code><code>// Add a link to the last page<br />
if (this.Page &lt; this.TotalPageCount - 2)<br />
{<br />
this.Controls.Add(new LiteralControl(" ... "));<br />
this.Controls.Add(this.CreateLink(this.TotalPageCount.ToString(), this.TotalPageCount));<br />
}<br />
}</code><code>// Add the next links<br />
if (this.Page &lt; this.TotalPageCount &amp;&amp; this.ShowPreviousNextLinks)<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateLink("›", this.Page + 1));<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateLink("»", this.TotalPageCount));<br />
}<br />
}</code><code>private void CreatePagerForCommand()<br />
{<br />
if (this.TotalRowCount &gt; this.PageSize)<br />
this.Controls.Add(new LiteralControl("Page:"));</code><code>// Add the previous links<br />
if (this.Page &gt; 1 &amp;&amp; this.ShowPreviousNextLinks)<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateCommand("First", "«", 1));<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateCommand("Previous", "‹", this.Page - 1));<br />
}</code><code>// Loop through the pages<br />
if (this.TotalRowCount &gt; this.PageSize)<br />
{<br />
for (int i = (this.Page &lt;= 2 ? 1 : this.Page - 2); i &lt;= (this.Page &gt;= this.TotalPageCount - 2 ? this.TotalPageCount : this.Page + 2); i++)<br />
{<br />
if (this.Page == i)<br />
this.Controls.Add(new LiteralControl(" &lt;u&gt;" + i.ToString() + "&lt;/u&gt;"));<br />
else<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateCommand("PageChange", i.ToString(), i));<br />
}<br />
}</p>
<p>// Add a link to the last page<br />
if (this.Page &lt; this.TotalPageCount - 2)<br />
{<br />
this.Controls.Add(new LiteralControl(" ... "));<br />
this.Controls.Add(this.CreateCommand("Last", this.TotalPageCount.ToString(), this.TotalPageCount));<br />
}<br />
}</p>
<p>// Add the next links<br />
if (this.Page &lt; this.TotalPageCount &amp;&amp; this.ShowPreviousNextLinks)<br />
{<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateCommand("Next", "›", this.Page + 1));<br />
this.Controls.Add(new LiteralControl(" "));<br />
this.Controls.Add(this.CreateCommand("Last", "»", this.TotalPageCount));<br />
}<br />
}</p>
<p>private HyperLink CreateLink(string text, int page)<br />
{<br />
HyperLink control = new HyperLink();<br />
control.Text = text;<br />
control.NavigateUrl = string.Format(this.Url, page);<br />
return control;<br />
}</p>
<p>private LinkButton CreateCommand(string commandName, string text, int page)<br />
{<br />
LinkButton control = new LinkButton();<br />
control.Text = text;<br />
control.CommandName = commandName;<br />
control.CommandArgument = page.ToString();<br />
control.Command += new CommandEventHandler(HandleEvent);<br />
return control;<br />
}</p>
<p>private void HandleEvent(Object sender, CommandEventArgs e)<br />
{<br />
this.Page = Convert.ToInt32(e.CommandArgument);<br />
OnPagerCommand(new PagerCommandEventArgs(this.StartRowIndex, this.PageSize, e));<br />
this.ChildControlsCreated = false;<br />
}<br />
}<br />
}</p>
<p></code>I&#8217;m not going to bore you with exactly what it does but instead show you a couple of examples of how it can be used.</p>
<p><strong>Without a DataSource control</strong></p>
<p>With the new control this is now pretty easy because the TotalRowCount property is not read only. All you have to do is set this property once you have bound your data, ie (GetData is a method which passes in the StartRowIndex and the MaximumRows and returns only the rows you want to display for that page and GetDataCount returns the total number of rows):</p>
<p><code>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!this.IsPostBack)<br />
{<br />
this.BindData(0);<br />
pager.TotalRowCount = this.GetDataCount();<br />
}<br />
}</code><code>protected void BindData(int startRowIndex)<br />
{<br />
lvwItems.DataSource = this.GetData(startRowIndex, pager.PageSize);<br />
lvwItems.DataBind();<br />
}</code><code>protected void pager_PagerCommand(Object sender, Flixon.Web.UI.WebControls.PagerCommandEventArgs e)<br />
{<br />
this.BindData(e.StartRowIndex);<br />
}</code></p>
<p>Then in your aspx file you reference the control in the standard way and put:</p>
<p><code>&lt;flixon:Pager ID="pager" runat="server" PageSize="15" OnPagerCommand="pager_PagerCommand" /&gt;</code></p>
<p><strong>Without a DataSoruce control (but using the query string to make it seo friendly)</strong></p>
<p>You could modify the above to:</p>
<p><code>&lt;flixon:Pager ID="pager" runat="server" PageSize="15" QueryStringField="Page" Url="/Default.aspx?Page={0}" /&gt;</code></p>
<p>The PagerCommand event is not necessary if we are using the query string therefore change the code behind file accordingly:</p>
<p><code>protected void Page_Load(object sender, EventArgs e)<br />
{<br />
if (!this.IsPostBack)<br />
{<br />
lvwItems.DataSource = this.GetData(pager.StartRowIndex, pager.PageSize);<br />
lvwItems.DataBind();<br />
pager.TotalRowCount = this.GetDataCount();<br />
}<br />
}</code></p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2008/04/28/custom-aspnet-data-pager-control/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Creating PDF Documents in ASP.Net</title>
		<link>http://www.flixon.com/2008/02/27/creating-pdf-documents-in-aspnet/</link>
		<comments>http://www.flixon.com/2008/02/27/creating-pdf-documents-in-aspnet/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 14:53:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2008/02/27/creating-pdf-documents-in-aspnet/</guid>
		<description><![CDATA[This article will quickly show you how to create pdf documents in ASP.Net.  To get started go to http://itextsharp.sourceforge.net/ and download the iTextSharp library.  Now add the library to your web site.  We can now begin creating a pdf document.
Step 1. Add a new web form to your website.
Step 2. Place the following at the top [...]]]></description>
			<content:encoded><![CDATA[<p>This article will quickly show you how to create pdf documents in ASP.Net.  To get started go to <a href="http://itextsharp.sourceforge.net/">http://itextsharp.sourceforge.net/</a> and download the iTextSharp library.  Now add the library to your web site.  We can now begin creating a pdf document.</p>
<p>Step 1. Add a new web form to your website.<br />
Step 2. Place the following at the top of your code behind file:</p>
<p><code>using iTextSharp.text;<br />
using iTextSharp.text.pdf;</code></p>
<p>Step 3. Finally place the following in the Page_Load event handler:</p>
<p><code>// Start pdf writer<br />
MemoryStream ms = new MemoryStream();<br />
Document document = new Document();<br />
PdfWriter.GetInstance(document, ms);</p>
<p>// Open the document for writing<br />
document.Open();</code><code>// Add a paragraph<br />
Paragraph paragraph = new Paragraph("Hello World");<br />
document.Add(paragraph);</p>
<p>// Close the document<br />
document.Close();</p>
<p>// Output the file<br />
Response.ContentType = "application/pdf";<br />
Response.Clear();<br />
Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);<br />
Response.End();</code></p>
<p>Obviously this is a very basic example but the iTextSharp is not too well documented for ASP.Net (c#) since it was innitially targetted for Java users.</p>
<p>Below is an example of adding an image to your pdf document (replace the path occordingly):</p>
<p><code>// Add an image<br />
Image logo = Image.GetInstance(Server.MapPath("~/Images/Image.jpg"));<br />
logo.ScaleAbsolute(100, 16);<br />
document.Add(logo);</code></p>
<p>The next example shows how you can add a new font and some text which uses that font:</p>
<p><code>// Arial font<br />
BaseFont arial = BaseFont.CreateFont(Server.MapPath("~/Fonts/Arial.ttf"), BaseFont.WINANSI, BaseFont.EMBEDDED);</p>
<p>// Add a paragraph<br />
Paragraph paragraph = new Paragraph();<br />
paragraph.Add(new Chunk("Text", new Font(arial, 14, Font.NORMAL, new Color(0, 125, 195))));<br />
website.Add(new Chunk("More Text", new Font(arial, 14, Font.NORMAL)));<br />
document.Add(paragraph);</code></p>
<p>Tables are also very simple to do. To add a table you create an instance of the Table class passing the number of columns you wish your table to have and then add it to the document as you have done above:</p>
<p><code>Table table = new Table(2); // 2 columns<br />
table.AddCell(new Cell("Row 1: Column: 1"));<br />
table.AddCell(new Cell("Row 1: Column: 2"));<br />
table.AddCell(new Cell("Row 2: Column: 1"));<br />
table.AddCell(new Cell("Row 2: Column: 2"));<br />
document.Add(table);</code></p>
<p>The final example shows how you can add a new page:</p>
<p><code>// Add a new page<br />
document.NewPage();</code></p>
<p>I hope this helps you grasp the basics of creating pdf documents in asp.net.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2008/02/27/creating-pdf-documents-in-aspnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>ASP.NET 2 Way Databinding Suggestions/Improvements</title>
		<link>http://www.flixon.com/2007/11/03/aspnet-2-way-databinding-suggestionsimprovements/</link>
		<comments>http://www.flixon.com/2007/11/03/aspnet-2-way-databinding-suggestionsimprovements/#comments</comments>
		<pubDate>Sun, 04 Nov 2007 01:24:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/11/03/aspnet-2-way-databinding-suggestionsimprovements/</guid>
		<description><![CDATA[Hi, i&#8217;ve searched the internet to see if others have documented this problem but i could not find anything so i thought i would post it here.  The problem i have is with 2 way databinding.
First off I must say that I am a big fan of 2 way databinding introduced in asp.net 2.0 but [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, i&#8217;ve searched the internet to see if others have documented this problem but i could not find anything so i thought i would post it here.  The problem i have is with 2 way databinding.</p>
<p>First off I must say that I am a big fan of 2 way databinding introduced in asp.net 2.0 but i feel it can be improved.  The main issue i have is that when you using Bind(&#8221;name&#8221;) the name must be the same both ways.  Imagine i have a DateTime field in my database and i have a calendar to handle the date.  Now i have three drop down lists to handle the time (one each for hour, minute and second).  I would set the SelectedValue for the hour to &lt;%# Bind(&#8221;Date&#8221;, &#8220;{0:HH}&#8221;) %&gt; but the name in my update method is DateHour.  The only way i can achieve this is to use Eval and then pass the value on the OnInserting/Updating event handler with the appropriate name.  My solution to this would be to have an additional databinding method called EvalBind (as an example) which you can pass 2 (or 3 if formatting) parameters.  The first would be for the Eval part and the second the Bind part.  Using the example above i could then say &lt;%# EvalBind(&#8221;Date&#8221;, &#8220;DateHour&#8221;, &#8220;{0:HH}&#8221;) %&gt;.<br />
 <br />
However i still have one further issue with the databinding syntax.  I am unable to easily add a default value to a control with 2 way databinding without using the code behind file.  Therefore i have come up with a better solution which would be to add an additional property to the controls called Bind (again as an example) and then i could say &lt;asp:DropDownList ID=&#8221;ddlDateHour&#8221; runat=&#8221;server&#8221; SelectedValue=&#8217;&lt;%# Eval(&#8221;Date&#8221;, &#8220;{0:HH}&#8221;) %&gt;&#8217; Bind=&#8221;DateHour&#8221;&gt;&#8230;&lt;/asp:DropDownList&gt; on my edit page and on my insert page i could set the SelectedValue (or Text for a TextBox) to a default value.<br />
 <br />
I know my examples are not brilliant but i have come across these problems many times.  Also both solutions above are backwards compatible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/11/03/aspnet-2-way-databinding-suggestionsimprovements/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pivot Tables with Dynamic Columns</title>
		<link>http://www.flixon.com/2007/10/29/pivot-tables-with-dynamic-columns/</link>
		<comments>http://www.flixon.com/2007/10/29/pivot-tables-with-dynamic-columns/#comments</comments>
		<pubDate>Mon, 29 Oct 2007 21:53:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/10/29/pivot-tables-with-dynamic-columns/</guid>
		<description><![CDATA[Hi, Recently i ran into a situation where i had to pivot/rotate a table (change rows to columns).  This makes it very easy to apply filtering and sorting on data which might have seen impossible to do before.  The site i used to help me is found at:
http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx
I found this a great resource and encourage anyone interested in [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, Recently i ran into a situation where i had to pivot/rotate a table (change rows to columns).  This makes it very easy to apply filtering and sorting on data which might have seen impossible to do before.  The site i used to help me is found at:</p>
<p><a href="http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx">http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspx</a></p>
<p>I found this a great resource and encourage anyone interested in this field to give it a read.  One particular case i found for doing this is when dealing with dynamic forms.  Imagine i have the following tables:</p>
<p>Attributes:<br />
 - AttributeID<br />
 - AttributeName</p>
<p>Documents:<br />
 - DocumentID<br />
 - Title</p>
<p>DocumentValues<br />
 - AttributeID<br />
 - DocumentID<br />
 - Value</p>
<p>The attributes are basically additional columns to the documents table that i can generate dynamically.  The values for a document&#8217;s attributes are then stored in the DocumentValues table.</p>
<p>I can then construct the following sql query (sql server 2005) which will inter-change the rows to columns and give me the benefits mentioned above:</p>
<p><code>DECLARE @Cols VARCHAR(2000)</code><code>SELECT @Cols = COALESCE(@Cols + ',[' + AttributeName + ']', '[' + AttributeName + ']')<br />
FROM Attributes<br />
ORDER BY AttributeName</p>
<p>SET @Query = N'SELECT Documents.*, ' + @Cols + ' FROM<br />
(SELECT DocumentValues.DocumentID, DocumentValues.Value, Attributes.AttributeName FROM Attributes INNER JOIN DocumentValues ON Attributes.AttributeID = DocumentValues.AttributeID) p<br />
PIVOT (<br />
MAX([Value])<br />
FOR AttributeName IN (' + @Cols + ')<br />
) AS DocumentValues INNER JOIN<br />
Documents ON DocumentValues.DocumentID = Documents.DocumentID'</p>
<p></code>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/10/29/pivot-tables-with-dynamic-columns/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Object reference not set to an instance of an object</title>
		<link>http://www.flixon.com/2007/10/12/object-reference-not-set-to-an-instance-of-an-object/</link>
		<comments>http://www.flixon.com/2007/10/12/object-reference-not-set-to-an-instance-of-an-object/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 07:51:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/10/12/object-reference-not-set-to-an-instance-of-an-object/</guid>
		<description><![CDATA[Hi, this post is more a reminder to myself but for a long time i kept getting the error &#8220;Object reference not set to an instance of an object&#8221; whilst running my asp.net websites even though the object was not null.  I searched google and found my answer at http://forums.aspfree.com/net-development-11/common-causes-of-object-reference-not-set-to-an-instance-45799.html.  You simply need to run (using [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, this post is more a reminder to myself but for a long time i kept getting the error &#8220;Object reference not set to an instance of an object&#8221; whilst running my asp.net websites even though the object was not null.  I searched google and found my answer at <a href="http://forums.aspfree.com/net-development-11/common-causes-of-object-reference-not-set-to-an-instance-45799.html">http://forums.aspfree.com/net-development-11/common-causes-of-object-reference-not-set-to-an-instance-45799.html</a>.  You simply need to run (using the command prompt):</p>
<p>aspnet_regiis -i</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/10/12/object-reference-not-set-to-an-instance-of-an-object/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adding an empty data template to the repeater control</title>
		<link>http://www.flixon.com/2007/09/26/8/</link>
		<comments>http://www.flixon.com/2007/09/26/8/#comments</comments>
		<pubDate>Wed, 26 Sep 2007 15:33:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/09/26/8/</guid>
		<description><![CDATA[Hi, i was looking around for an article on how to extend the repeater control to add an empty data template similar to the GridView control.  Here is a link to the the article i found.  However i discovered that it rendered the header and footer, so i set about creating my own one and come [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, i was looking around for an article on how to extend the repeater control to add an empty data template similar to the GridView control.  <a href="http://weblogs.asp.net/acampbell/archive/2004/06/19/159780.aspx">Here is a link</a> to the the article i found.  However i discovered that it rendered the header and footer, so i set about creating my own one and come up with the following:</p>
<p><code>using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Text;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;</code></p>
<p><code></code><code>namespace ControlLibrary<br />
{<br />
  public class Repeater : System.Web.UI.WebControls.Repeater<br />
  {<br />
  private ITemplate _emptyDataTemplate;</code><code>[Browsable(false)]<br />
  [PersistenceMode(PersistenceMode.InnerProperty)]<br />
  public ITemplate EmptyDataTemplate<br />
  {<br />
  get { return _emptyDataTemplate; }<br />
  set { _emptyDataTemplate = value; }<br />
  }</code><code>protected override void Render(HtmlTextWriter output)<br />
  {<br />
  // If there is no data then we don't wish to render anything (including the header and the footer)<br />
  if (this.Items.Count == 0)<br />
  {<br />
  // If an empty data template has been provided then display it<br />
  if (this.EmptyDataTemplate != null)<br />
  {<br />
  PlaceHolder phdTemplate = new PlaceHolder();<br />
  this.EmptyDataTemplate.InstantiateIn(phdTemplate);<br />
  phdTemplate.RenderControl(output);<br />
  }<br />
  }<br />
  else<br />
  base.Render(output);<br />
  }<br />
  }<br />
}</code></p>
<p><code></code>Now all you have to do is say:</p>
<p><code><br />
&lt;%@ Register TagPrefix=”Flixon” Namespace=”ControlLibrary” Assembly=”ControlLibrary” %&gt;<br />
&lt;Flixon:Repeater&gt;<br />
    &lt;ItemTemplate&gt;<br />
          &lt;%# Container.DataItem %&gt;<br />
    &lt;/ItemTemplate&gt;<br />
    &lt;EmptyDataTemplate&gt;<br />
         No data returned!<br />
    &lt;/EmptyDataTemplate&gt;<br />
&lt;/Flixon:Repeater&gt;<br />
</code></p>
<p>on your page and you&#8217;re done.</p>
<p>I hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/09/26/8/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Return all results within a category including sub categories</title>
		<link>http://www.flixon.com/2007/09/10/return-all-results-within-a-category-including-sub-categories/</link>
		<comments>http://www.flixon.com/2007/09/10/return-all-results-within-a-category-including-sub-categories/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 16:03:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/09/10/return-all-results-within-a-category-including-sub-categories/</guid>
		<description><![CDATA[Hi, i recently ran in to a situation where i had to return every article in my database that was under a particular category (including all articles within the sub categories, sub sub categories and so on).  The Categories table relates a sub category to a category by a ParentID.
At first i went along the [...]]]></description>
			<content:encoded><![CDATA[<p>Hi, i recently ran in to a situation where i had to return every article in my database that was under a particular category (including all articles within the sub categories, sub sub categories and so on).  The Categories table relates a sub category to a category by a ParentID.</p>
<p>At first i went along the lines of a recursive sql statement but this caused problems when there was no articles in one of the top level categories (not an easy problem to spot).  The solution i finally come up with was one i particularly like as it meant i did not have to modify my query much.  I simply add the following function:</p>
<p><code>CREATE FUNCTION [dbo].[GetCategories]<br />
 (<br />
 @ParentID INT,<br />
 @Output VARCHAR(255)<br />
 )<br />
RETURNS VARCHAR(255)<br />
AS<br />
BEGIN<br />
 IF @Output = ''<br />
 BEGIN<br />
  SET @Output = Convert(VARCHAR(255), @ParentID)<br />
 END</code><code>DECLARE @CategoryID INT<br />
 DECLARE c1 CURSOR FOR SELECT CategoryID FROM Categories WHERE ParentID = @ParentID<br />
 OPEN c1<br />
 FETCH NEXT FROM c1 INTO @CategoryID<br />
 WHILE @@FETCH_STATUS = 0<br />
 BEGIN<br />
  SET @Output = @Output + ', ' + Convert(VARCHAR(255), @CategoryID)<br />
  SET @Output = dbo.GetCategories(@CategoryID, @Output)<br />
  FETCH NEXT FROM c1 INTO @CategoryID<br />
 END<br />
 CLOSE c1<br />
 DEALLOCATE c1</code><code>RETURN @Output<br />
END</code></p>
<p>Now i could execute the following query:</p>
<p><code>SELECT * FROM Articles WHERE CategoryID IN dbo.GetCategories(1, '')</code></p>
<p>And it would return all the articles where the CategoryID is 1 or the category is a sub of the category specified.</p>
<p>Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/09/10/return-all-results-within-a-category-including-sub-categories/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Working with database fields that allow nulls</title>
		<link>http://www.flixon.com/2007/07/28/working-with-database-fields-that-allow-nulls/</link>
		<comments>http://www.flixon.com/2007/07/28/working-with-database-fields-that-allow-nulls/#comments</comments>
		<pubDate>Sat, 28 Jul 2007 18:25:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/07/28/working-with-database-fields-that-allow-nulls/</guid>
		<description><![CDATA[I know asp.net 2.0 has been out for a while now but i&#8217;ve only recently setup this blog and thought i should post an article on something that troubled me for a while as a newcomer to asp.net, i am talking of database fields that allow null values.
First i would like to start with how [...]]]></description>
			<content:encoded><![CDATA[<p>I know asp.net 2.0 has been out for a while now but i&#8217;ve only recently setup this blog and thought i should post an article on something that troubled me for a while as a newcomer to asp.net, i am talking of database fields that allow null values.</p>
<p>First i would like to start with how i tackled the problem of casting the data returned from the database to the correct data types.  With the help of a website i have forgotten the address of, i use the following method:</p>
<p><code>public static T CastTo&lt;T&gt;(object value)<br />
{<br />
    return value != DBNull.Value ? (T)value : default(T);<br />
}</code></p>
<p>Then all i have to do is wrap my data returned using a DataReader with this method, ie int? categoryID = CastTo&lt;int?&gt;(reader[&#8221;CategoryID&#8221;]).</p>
<p>The second problem when working with null database fields is making sure that you store a null value when inserting/updating data.  For this problem i wanted an expression that didn&#8217;t mean i had to write much extra code and was consistent for all data types.  The following example shows how to update a field that allows null fields using a nullable type:</p>
<p><code>using (SqlConnection cn = new SqlConnection(this.ConnectionString))<br />
{<br />
    int? categoryID = null;<br />
    SqlCommand cmd = new SqlCommand("UPDATE Documents SET CategoryID = @CategoryID WHERE DocumentID = @DocumentID", cn);<br />
    cmd.Parameters.Add("@DocumentID", SqlDbType.Int).Value = 1;<br />
    cmd.Parameters.Add("@CategoryID", SqlDbType.Int).Value = (object)categoryID ?? DBNull.Value;<br />
    cn.Open();<br />
    cmd.ExecuteNonQuery()<br />
}</code></p>
<p>What i personally like about the code above is when adding the parameter i can keep it on one line and it works for any data type.  Please note that you must pass DBNull.Value instead of null as the value for your parameter.  If passing null asp.net will treat it as if no parameter was added and an exception will be thrown.</p>
<p>I hope this approach helps you as much as it has helped me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/07/28/working-with-database-fields-that-allow-nulls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>VS 2008 and .NET 3.5 Beta 2 Released</title>
		<link>http://www.flixon.com/2007/07/27/vs-2008-and-net-35-beta-2-released/</link>
		<comments>http://www.flixon.com/2007/07/27/vs-2008-and-net-35-beta-2-released/#comments</comments>
		<pubDate>Fri, 27 Jul 2007 16:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flixon.com/2007/07/27/vs-2008-and-net-35-beta-2-released/</guid>
		<description><![CDATA[Scott Guthrie has today posted news on the release of Visual Studio 2008 and .NET 3.5 Beta 2 here.  Please make sure you read his post carefully as he has posted important information for users upgrading from Visual Studio 2005 who have been using Ajax within their ASP.NET 2.0 websites.  A Silverlight update is also scheduled [...]]]></description>
			<content:encoded><![CDATA[<p>Scott Guthrie has today posted news on the release of Visual Studio 2008 and .NET 3.5 Beta 2 <a target="_blank" href="http://weblogs.asp.net/scottgu/archive/2007/07/26/vs-2008-and-net-3-5-beta-2-released.aspx" title="VS 2008 and .NET 3.5 Beta 2 Released">here</a>.  Please make sure you read his post carefully as he has posted important information for users upgrading from Visual Studio 2005 who have been using Ajax within their ASP.NET 2.0 websites.  A Silverlight update is also scheduled within the next few days.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flixon.com/2007/07/27/vs-2008-and-net-35-beta-2-released/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
