无为清净楼资源网 Design By www.qnjia.com

网址其实就是目录文件的影射。因此只要拆分URL,并且根据URL的层级关系进行循环,就可以得到当前导航文件的目录。

1、建立数据库表:Navigate
列名 数据类型 说明 id int parentId int 父ID root int 层级,0代表根目录,最顶层 pathName varchar(50) (URL)路径名称 navName varchar(50) (栏目)导航名称

2、建立用户控件 navigate.ascx
-----------------------------------------------------------
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Navigate.ascx.cs" Inherits="UC_Navigate" %>
<div style="display:block;margin-top:5px;margin-left:3px;margin-bottom:5px;">

     您当前的位置:<a href="/index.aspx">首页</a> 
      
      <asp:Label ID="lblNavigate" runat="server"></asp:Label>
      <asp:Label ID="lblTitle" runat="server"></asp:Label>

</div>


3、用户控件的CS后台文件 navigate.ascx.cs
-----------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Bai51.Data;

public partial class UC_Navigate : System.Web.UI.UserControl
{
    private string localUrl="http://localhost:8085";
    private string title;
    private DataSet ds;
    private DataTable dt;

    protected void Page_Load(object sender, EventArgs e)
    {

        #region -- 获取导航信息表内容(缓存) --
        ds=(DataSet)Cache["dsNavigateCache"];
        if(ds==null)
       {
         ds=SqlComd.CreateSqlDataSet("select * from navigate","dsNavigate"); 
         Cache.Insert("dsNavigateCache",ds,null,System.Web.Caching.Cache.NoAbsoluteExpiration,TimeSpan.FromHours(24));
       }
       dt=ds.Tables[0];
        #endregion

         #region -- 生成导航信息 --
        //分割当前URL地址
        string[] webUrl = System.Web.HttpContext.Current.Request.Path.Split(new char[] { '/' });
        int len = webUrl.Length - 1;

        //层级循环
        string strUrl = localUrl + "/";
        string strNavigate = "";
        string parenId = "0";

        for (int i = 1; i < len; i++)
        {
            string sql = "root=" + Convert.ToString(i-1) + " and pathName='" + webUrl[i] + "' and parentId=" + parenId;
            DataRow[] rows = dt.Select(sql);

            //循环连接地址
            strUrl += (webUrl[i] + "/");
            strNavigate += "<a href='" + strUrl + "'>" + rows[0]["navName"].ToString() + "</a>" + " ";

            //保存父ID
            parenId = rows[0]["Id"].ToString();
        }
       #endregion

        lblNavigate.Text=strNavigate;
        lblTitle.Text=title ;
    }

    #region --控件属性 --
    public string LocalUrl
    {
        get{return  localUrl;}
        set{ localUrl=value ;}
    }
    public string Title
    {
        get { return title; }
        set { title = value; }
    }
    #endregion   

}

4、使用方法
-----------------------------------------------------------
在页面中拖入 Navigate.ascx 用户控件,命名为"navBar"。
在后台代码中写入当前文件的导航名称即可。
      navBar.Title = "本页面是XX栏目";

标签:
使用UserControl做网站导航条的思路,分析

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。