我制作了一个用户控件,可以在我的页面上生成一个超链接列表。问题是它似乎不想工作。这是我的用户控件代码:
<%@ Control Language="C#" AutoEventWireup="True" CodeBehind="DepartmentsList.ascx.cs"
Inherits="BaloonShop.UserControls.DepartmentsList" %>
<asp:DataList ID="list" runat="server" CssClass="departmentslist" Width="200px">
<HeaderStyle CssClass="departmentslisthead" />
<HeaderTemplate>
Choose a Department
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Classes.Link.ToDepartment(Eval("DepartmentID").ToString())%>'
Text='<%# HttpUtility.HtmlEncode(Eval("Name").ToString()) %>'
ToolTip='<%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %>'
CssClass='<%# Eval("DepartmentID").ToString() == Request.Querystring["DepartmentID"] ? "departmentselected" : "departmentunselected" %>'>
</asp:HyperLink>
</ItemTemplate>
我的文件结构如下:
为什么说找不到Classes文件夹?
如果您需要更多信息,请询问。
编辑
链接类代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace BaloonShop.Classes
{
/// <summary>
/// Link factory class
/// </summary>
public class Link
{
// Builds an absolute URL
private static string BuildAbsolute(string relativeUri)
{
// get current uri
Uri uri = HttpContext.Current.Request.Url;
// build absolute path
string app = HttpContext.Current.Request.ApplicationPath;
if (!app.EndsWith("/")) app += "/";
relativeUri = relativeUri.TrimStart('/');
// return the absolute path
return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUri));
}
// Generate a department URL
public static string ToDepartment(string departmentId, string page)
{
if (page == "1")
return BuildAbsolute(String.Format("Catalog.aspx?DepartmentID={0}", departmentId));
else
return BuildAbsolute(String.Format("Catalog.aspx?DepartmentId={0}&Page={1}", departmentId, page));
}
// Generate a department URL for the first page
public static string ToDepartment(string departmentId)
{
return ToDepartment(departmentId, "1");
}
}
}