正在阅读:用Asp.net制作顶部导航控件用Asp.net制作顶部导航控件

2005-08-19 10:18 出处:PConline 作者:∮明天去要饭 责任编辑:xietaoming

  方法1:显示所有一级栏目

  该方法是点击“首页”时或者是第一次打开网页的时候调用的,实现的效果为加粗“首页”两字,并改变“首页”所在的单元格的背景。该方法命名为:showFirstMenu(),代码如下:

public void showFirstMenu()
         {
                            //读取所有Parentsroot的记录(也就是所有一级栏目),升序排列,下同
              DataView dv = ReadXmlDataView("HeadMenu.xml","Parents = 'root'","OrderID asc");
              //保存从xml中读取出来的栏目的链接地址
              string strLinkUrl;
              //保存读出来的栏目名称
              string strTitle;
              //判断是否有一级栏目
              if(dv.Count > 0)
              {
                   //先清空label的内容,防止上次生成的内容遗留下来
                   lblCode.Text = "";               
                   //生成一级栏目表格-------------------------------
                   lblCode.Text = "<table width='100%'  border='0' align='center' cellpadding='0' cellspacing='0' class='Cn12Black'>";
                   lblCode.Text += "<tr><td width='100%' height='3' class='bgGray'></td></tr>";
                   lblCode.Text += "<tr><td class='bgGray'>";
                   lblCode.Text += "<table height='30'  border='0' cellpadding='3' cellspacing='0'>";
                   lblCode.Text += "<tr>";
 
                   //循环读出一级栏目
                   for(int i=0; i < dv.Count; i++)
                   {                      
                       strLinkUrl = dv[i]["LinkUrl"].ToString().Trim();
                       strTitle = dv[i]["Title"].ToString().Trim();
                       //如果是首页,加粗及改变其单元格背景色,如果你的首页不是default.aspx,则修改为你的首页,xml中也要修改
                       if(strLinkUrl.Equals("default.aspx"))
                       {
                            lblCode.Text += "<td class='Cn12Gray'>|</td>";
                            //改变首页单元格背景的颜色,该颜色用cssbgGray1定义。
                            lblCode.Text += "<td class='bgGray1'>";
                            //首页指定的链接
                            lblCode.Text += "<a href='" + strLinkUrl + "' class=navPad>";
                            //加粗首页两个字
                            lblCode.Text += "<strong>" + strTitle + "</strong>";
                            lblCode.Text += "</a>";
                            lblCode.Text += "</td>";
                       }
                       else
                       {
                            lblCode.Text += "<td class='Cn12Gray'>|</td>";
                            lblCode.Text += "<td>";
                            lblCode.Text += "<a href='" + strLinkUrl + "' class=navPad>";
                            lblCode.Text += strTitle;
                            lblCode.Text += "</a>";
                            lblCode.Text += "</td>";
                       }
                   }
                   lblCode.Text += "</tr></table>";
                   //显示二级栏目
                   lblCode.Text += "</td></tr>"; 
                   //一级栏目html代码到这里结束--------------------------
 
                   //显示二级栏目,由于访问首页时二级栏目为空,所以此行高度调小,并且无内容显示
                   lblCode.Text += "<tr><td height='10' class='bgGray1'>";
                   lblCode.Text += "</td></tr>";
                   lblCode.Text += "</table>";
                   
                   //显示当前位置为首页        
 
                   lblPosition.Text = "";
                   lblPosition.Text += "<table width='100%'  border='0' cellspacing='0' cellpadding='6'><tr><td class='Cn12BlackStrong'>";
                   //如果在“当前位置”前不想要图片,把<img src='images/icon_alert.gif' width='16' height='16' align='absbottom'>去掉就行了
                   lblPosition.Text += "<img src='images/icon_alert.gif' width='16' height='16' align='absbottom'>当前位置:<a href='default.aspx'>首页</a>";
                   lblPosition.Text += "</td></tr></table>";
     }

键盘也能翻页,试试“← →”键

相关文章

关注我们

最新资讯离线随时看 聊天吐槽赢奖品