一个导航条的例子

来源:互联网 发布:云计算工程师的收入 编辑:程序博客网 时间:2024/04/25 09:34

本文链接:http://user.qzone.qq.com/361983679/blog/1211386526

大家快做项目了, 一定会想到过自己的导航条怎么做呢,这是我做的一个小例子,我个人让为呢还行,有那位朋友想用的话,我苏飞原把所有源码奉上,呵呵别忘了给我留言啊!!!!
在.aspx源在的代码

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Src="Menus.ascx" TagName="Menus" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
    <script language ="javascript" type ="text/javascript">
function showsubmenu(sid)
{
 whichEl = eval("document.getElementById('"+"submenu" + sid+"')");
 imgmenu = eval("document.getElementById('"+"imgmenu" + sid+"')");
 if (whichEl.style.display == "none")
 {
  if (whichEl.style.display=='none') whichEl.style.display='';
   else whichEl.style.display = 'none';
  imgmenu.background="image/menuup.gif";
 }
 else
 {
  if (whichEl.style.display=='none') whichEl.style.display='';
   else whichEl.style.display = 'none';
  imgmenu.background="image/menudown.gif";
 }
}
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;</div>
        <asp:Label ID="Label1" runat="server" Height="464px" Style="z-index: 100; left: 286px;
            position: absolute; top: 82px; width: 165px;" Text="Label"
        BackColor="#6666FF" BorderColor="#FF5050" BorderWidth="2px"></asp:Label>
    </form>
</body>

</html>

在.aspx.cs中的代码

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    /**
     *2008年4月12号在宿舍作
     *我是苏飞有什么看不明白的找我吧!
     */
    public string text;
    DataTable BT, ST;
    protected void Page_Load(object sender, EventArgs e)
    {
        text = MenuLoad();
        Label1.Text = text;//把得到的结果放到一个label中去

    }
    private DataTable executquery( string straql,string tablename)//此方法用于执行传过来的sql语句,并返回一DataTable
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=doughty_bbs;Integrated Security=True");
        con.Open();
        SqlDataAdapter datapadter = new SqlDataAdapter(straql ,con);
        DataSet datset = new DataSet();
        datapadter.Fill(datset ,tablename);
        con.Close();    
        return datset.Tables[tablename];
      
    }
    private string MenuLoad()
    {
        //填充树干的内容
        string trees = "", bs = "";
        int i = 1;
        //查询Big_Class表
        string strsql1 = "SELECT BigClass_ID, BigClass_Name, Enable FROM Big_Class WHERE (Enable = 1)";
        BT = executquery(strsql1, "Big_Class");
        //查询Small_Class表
        string strsql2="SELECT SmallClass_ID, BigClass_ID, SmallClass_Name, Enable FROM Small_Class WHERE (Enable = 1)";
        ST = executquery(strsql2, "Small_Class");
        DataRow[] drs = BT.Select("");//调用extc

        foreach (DataRow r in drs)
        {
            trees += "<TABLE border=0 cellPadding=0 cellSpacing=0><TR height=2><TD></TD></TR></TABLE><TABLE width=158 border=0 align='center' cellPadding=0 cellSpacing=0 bgcolor=White><TBODY>";
            bs = "<A href=" + "sufei.aspx?BID=" + r["bigclass_ID"].ToString() + " target='mainFrame'>" + r["bigclass_Name"].ToString() + "</A>";
            trees += "<TR><TD height=25 background='image/menudown.gif' id='imgmenu"+ i + "'style='CURSOR: hand' onclick='showsubmenu(" + i + ")'>&nbsp;&nbsp;<SPAN>" + bs + "</SPAN></TD></TR> <TR><TD id='submenu" + i + "' style='DISPLAY: none'><DIV align='left'><TABLE width='90%' cellPadding=0 cellSpacing=3><TBODY>";
            string parentid = r["bigclass_ID"].ToString();
            trees += CreateNode(parentid) + "</TBODY></TABLE></DIV></TD></TR></TBODY></TABLE>";
            i++;
        }
        return trees;
    }
    private string CreateNode(string parentid)
    {
        //填充树枝的内容
        string Nodes = "";
        DataRow[] drsr = ST.Select("BigClass_ID = " + parentid);
        foreach (DataRow rw in drsr)
        {
            Nodes = Nodes + "<TR><TD><FONT color=#ff0000>·</FONT><A href=" + "sufei.aspx" + "?solved=0&BID=" + rw["bigclass_ID"].ToString() + "&SID=" + rw["SmallClass_ID"].ToString() + "&Page=1 target='mainFrame'>" + rw["SmallClass_Name"].ToString() + "</A></TD></TR>";
        }
        return Nodes;
    }
}
sql数据库


原创粉丝点击