Building menu in C#
<p>This is what I've done:</p>

<pre class="lang-xml prettyprint-override"><code>&lt;asp:Menu
    id="Menu1"
    Orientation="Horizontal"
    Runat="Server"&gt;
    &lt;StaticMenuStyle
        BackColor="#eeeeee" 
        BorderStyle="solid" 
        BorderColor="Black"
        BorderWidth="1" /&gt;
    &lt;DynamicMenuStyle 
        BackColor="#eeeeee" 
        BorderStyle="solid" 
        BorderColor="Black"
        BorderWidth="1" /&gt;
&lt;/asp:Menu&gt;
</code></pre>

<p>In the code behind:</p>

<pre class="lang-cs prettyprint-override"><code>if (!IsPostBack)
{
    DataSet dst = GetMenuData();
    foreach (DataRow masterRow in dst.Tables["Menu"].Rows)
    {
        if ((string)masterRow["parentitemid"] != "NULL" ||
            (string)masterRow["parentitemid"] != "")
        {
            MenuItem masterItem = new MenuItem((string)masterRow["parentitemid"]);
            Menu1.Items.Add(masterItem);
            foreach (DataRow childRow in masterRow.GetChildRows("Menu"))
            {
                MenuItem childItem = new MenuItem((string)childRow["ID"]);
                masterItem.ChildItems.Add(childItem);
            }
        }
    }
}
</code></pre>

<p>Basically, I'm trying to bind menu from database.  However I get this error:</p>

<blockquote>
  <p>Unable to cast object of type 'System.DBNull' to type 'System.String'.</p>
</blockquote>

<p>This is my database table:</p>

<pre class="lang-none prettyprint-override"><code>   ID          parentitemid        text                Url
   1            NULL           folder1         /folder1
   2            folder1     WebForm1.aspx   /folder1/WebForm1.aspx
   3            folder1     WebForm2.aspx   /folder1/WebForm2.aspx
   6              null          folder3     /folder3
   7            folder3     WebForm1.aspx   /folder3/WebForm1.aspx
   8            folder3     WebForm2.aspx   /folder3/WebForm2.aspx
   9            folder3     WebForm3.aspx   /folder3/WebFomr3.aspx
</code></pre>

<p>So, can you please help me fill the menu.</p>
