Forum Moderators: open
I have developed the CSS for my navigation menu that I would like to use for my .NET app. You can see it here:
snipped
The XHTML code for this is basically:
<div id="mainnav">
<h6>Bikes</h6>
<ul>
<li><a href="#">Specialized</a></li>
<li><a href="#">Kona</a></li>
<li><a href="#">Marin</a></li>
<li><a href="#">Orange</a></li>
<li><a href="#">GT</a></li>
<li><a href="#">Whyte</a></li>
<li><a href="#">Cove</a></li>
<li><a href="#">Santa Cruz</a></li>
</ul>
<h6>Drivetrain</h6>
<ul>
<li><a href="#">Rear Gear Derailleurs</a></li>
<li><a href="#">Front Gear Derailleurs</a></li>
<li><a href="#">Cassettes</a></li>
<li><a href="#">Cranksets</a></li>
<li><a href="#">Chains</a></li>
<li><a href="#">Bottom Brackets</a></li>
<li><a href="#">Gear Cables</a></li>
</ul>
<h6>Frames & Forks</h6>
<ul>
<li><a href="#">Suspension Forks</a></li>
<li><a href="#">Rigid Frames</a></li>
<li><a href="#">Hardtail Frames</a></li>
<li><a href="#">Suspension Frames</a></li>
<li><a href="#">Rear Shocks</a></li>
</ul>
</div>
I have a table in my SQL Server 2000 databases which containd all the categories that you can see in the menu. The structure is as follows:
-categoryID,
-category_name,
-parentID, (so I can have subcategories in the same table)
-description
Whats the best method to generate the menu dynamically in .NET using C#?
The headers (eg: Bikes) do not have parentID's so I would like these placed in the <h6> tags. And then all the other categories placed in the unordered list under the appropriate <h6> tag.
Any ideas?
Many thanks indeed :)
[edited by: DaveAtIFG at 6:58 pm (utc) on July 19, 2004]
[edit reason] URL Removed [/edit]
string subquery = "SELECT subcategoryID, categoryID, subcategory_name FROM SubCategories";
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = sqlConnection.ConnectionString;SqlDataAdapter da = new SqlDataAdapter(subquery,sqlConn);
DataSet ds = new DataSet();
DataRelation sqlRelation;da.Fill(ds, "SubCategories");
da.SelectCommand = new SqlCommand ("SELECT categoryID, category_name FROM Categories", sqlConn);
da.Fill(ds, "Categories");sqlRelation = new DataRelation("SubCategoriesParents", ds.Tables["Categories"].Columns["categoryID"], ds.Tables["SubCategories"].Columns["categoryID"]);
ds.Relations.Add(sqlRelation);foreach (DataRow drParent in ds.Tables["Categories"].Rows)
{
relationsLB.Text += "<h6>" + drParent["category_name"] + "</h6>";
foreach (DataRow drChild in drParent.GetChildRows("SubCategoriesParents"))
{
relationsLB.Text += "<li><a href=\"products.aspx?sub=" + drChild["subcategoryID"] + "\">" + drChild["subcategory_name"] + "</a></li>";
}
}
Cheers :)