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

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

  方法2:重新显示一级栏目

  该方法是点击除了“首页”这一链接以外的一级栏目时调用的,实现的效果为重新显示一级栏目,加粗当前点击的一级栏目名称,并改变其单元格背景颜色。同时显示属于该一级栏目的二级栏目。方法命名为:showFirstMenuByFile(strNowViewFile),传入的参数为当前浏览的文件名称。代码如下:

public void showFirstMenuByFile(string strNowViewFile)
         {
              //读取所有Parentsroot的记录
              DataView dv = ReadXmlDataView("HeadMenu.xml","Parents = 'root'","OrderID asc");
              //保存栏目的链接地址
              string strLinkUrl;
              //保存栏目名称
              string strTitle;
 
              if(dv.Count > 0)
              {
                   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();
 
                       //如果读出来的栏目名称为当前访问的一级栏目的名称,加粗并改变其单元格背景色
                       if(strLinkUrl.Equals(strNowViewFile))
                       {
                            lblCode.Text += "<td class='Cn12Gray'>|</td>";
                            lblCode.Text += "<td class='bgGray1'>";
                            lblCode.Text += "<a href='" + strLinkUrl + "' class=navPad>";
                            lblCode.Text += "<strong>" + strTitle + "</strong>";
                            lblCode.Text += "</a>";
                            lblCode.Text += "</td>";
                            
                            //改变当前位置-------------------------------------                                     
 
                            lblPosition.Text = "";
                            lblPosition.Text += "<table width='100%'  border='0' cellspacing='0' cellpadding='6'><tr><td class='Cn12BlackStrong'>";
                            lblPosition.Text += "<img src='images/icon_alert.gif' width='16' height='16' align='absbottom'>当前位置:<a href='default.aspx'>首页</a>";
                            lblPosition.Text += " >> <a href='" + strLinkUrl + "'>" + strTitle + "</a>";
                            lblPosition.Text += "</td></tr></table>";
                       }
                       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>";               
                   //一级栏目html代码到这里结束
                   lblCode.Text += "</td></tr>";
              }
     }

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

相关文章

关注我们

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