0
我正在使用一個新聞字母系統。我想知道如何在這裏使用JavaScript繪製分層菜單控件是article。如何使用JavaScript與asp.net 4.0繪製分層菜單控件
我試過了建立我的代碼,因爲它是:
App_Code文件/ SooperFish.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.Net.Mail;
using System.Data;
using System.Data.SqlClient;
using System.Net;
/// <summary>
/// Summary description for NlevelMenu
/// </summary>
public class SooperFish
{
string ConnectionString, ErrorMsg;
public object ApiProcedure { get; private set; }
public CredentialCache Credentials { get; private set; }
public SooperFish()
{
//Read Connection String From web.config
ConnectionString = WebConfigurationManager.ConnectionStrings["EASYMAILConnectionString"].ConnectionString;
}
public string GenerateXmlFormat()
{
string SqlCommand;
DataSet DbMenu;
DataRelation relation;
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
SqlCommand = "SELECT[MenuID],[MenuName],[MenuLocation],[ParentMenuID] FROM [EASYMAIL].[dbo].[tbl_Menu_master] WHERE [type_id] = " + int.Parse(HttpContext.Current.Session["TypeID"].ToString()) + " AND [IsActive] = 1 ";
DbMenu = new DataSet();
SqlDataAdapter Adapter = new SqlDataAdapter(SqlCommand, conn);
Adapter.Fill(DbMenu);
Adapter.Dispose();
}
DbMenu.DataSetName = "Menus";
DbMenu.Tables[0].TableName = "Menu";
//create Relation Parent and Child
relation = new DataRelation("ParentChild", DbMenu.Tables["Menu"].Columns["MenuID"], DbMenu.Tables["Menu"].Columns["ParentMenuID"], true);
relation.Nested = true;
DbMenu.Relations.Add(relation);
return DbMenu.GetXml();
}
public string ExecuteXSLTransformation()
{
string HtmlTags, XsltPath;
MemoryStream DataStream = default(MemoryStream);
StreamReader streamReader = default(StreamReader);
try
{
//Path of XSLT file
XsltPath = HttpContext.Current.Server.MapPath("XsltFormatFolder/XsltTransformer.xslt");
//Encode all Xml format string to bytes
byte[] bytes = Encoding.ASCII.GetBytes(GenerateXmlFormat());
DataStream = new MemoryStream(bytes);
//Create Xmlreader from memory stream
XmlReader reader = XmlReader.Create(DataStream);
// Load the XML
XPathDocument document = new XPathDocument(reader);
XslCompiledTransform XsltFormat = new XslCompiledTransform();
// Load the style sheet.
XsltFormat.Load(XsltPath);
DataStream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(DataStream, Encoding.ASCII);
//Apply transformation from xml format to html format and save it in xmltextwriter
XsltFormat.Transform(document, writer);
streamReader = new StreamReader(DataStream);
DataStream.Position = 0;
HtmlTags = streamReader.ReadToEnd();
return HtmlTags;
}
catch (Exception ex)
{
ErrorMsg = ex.Message;
return ErrorMsg;
}
finally
{
//Release the resources
streamReader.Close();
DataStream.Close();
}
}
}
MenuControl.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuControl.ascx.cs" Inherits="MenuControl"%>
<link rel="stylesheet" type="text/css" href="css/sooperfish.css" media="screen"/>
<link rel="stylesheet" type="text/css" href="css/sooperfish-theme-large.css" media="screen"/>
<script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easing-sooper.js"></script>
<script type="text/javascript" src="js/jquery.sooperfish.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('ul.sf-menu').sooperfish();
});
</script>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
MenuControl代碼
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Text;
using AjaxControlToolkit;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using ICSharpCode.SharpZipLib.Zip;
using System.Collections.Specialized;
using System.Data.OleDb;
using System.Net.Mail;
using System.Data.Linq.SqlClient;
using OpenPop.Pop3;
using OpenPop.Mime;
using OpenPop.Mime.Header;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Resolvers;
public partial class MenuControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SooperFish spoorfishMenu = new SooperFish();
Literal1.Text = spoorfishMenu.ExecuteXSLTransformation();
}
}
}
怎麼這不工作,因爲500內部錯誤發生在Web請求。