Re: AJAX Menu from XML hi,
i hope it may help you.
make your aspx page like this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function call()
{
document.getElementById("show").style.left="5px";
document.getElementById("show").style.top="40px";
document.getElementById("show").style.display="blo ck";
}
function call1()
{
document.getElementById("show").style.display="non e";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table>
<tr>
<td valign="middle" width="76" onmouseover="call()" onmouseout="call1()">
<a href="#">Product</a>
<div runat="server" id="show" style="display: none; position: absolute; border-bottom: solid 1px #dcdcdc;
border-left: solid 1px #dcdcdc; border-right: solid 1px #dcdcdc;">
<%# menu()%>
</div>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
in codebehind:
using System.Xml;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.DataBind();
}
protected string menu()
{
try
{
XmlDataDocument xmlDoc = new XmlDataDocument();
xmlDoc.Load(Server.MapPath("ProductList.xml"));
XmlNodeList xlist = xmlDoc.GetElementsByTagName("Product");
string showmenu = "";
showmenu = "<table cellspacing=5 width=150px runat=\"server\" align=\"left\" id=\"check\" style=\"background-color:White\" >";
for (int i = 0; i < xlist.Count; i++)
{
showmenu = showmenu + "<tr id=\"n" + i + "\" onmouseout=\"call3('n" + i + "')\" runai=\"server\" onmouseover=\"call2('n" + i + "')\" align=\"left\" ><td><a style=\"text-decoration:none;font-family: Tahoma;font-size: 11px;color: #7F7F7F;\" href=\"ParticularProduct.aspx?productId=" + xlist[i].ChildNodes[0].InnerText + "\"> " + xlist[i].ChildNodes[1].InnerText + " & nbsp; &nb sp;</a></td></tr>";
}
showmenu = showmenu + "</table>";
return showmenu;
}
catch
{
return "";
}
}
} |