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

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

  方法3:显示属于当前访问的一级栏目的二级栏目

  该方法只显示一级栏目下的二级栏目,并不需要实现加粗和改变单元格背景这效果。该方法命名为:showSecondMenu(strNowViewFile)。代码如下:

         public void showSecondMenu(string strNowViewFile)
         {             
              //根据传入的当前该问的文件查找当前访问的栏目名称             
              DataView dvNowMenu = ReadXmlDataView("HeadMenu.xml","LinkUrl = '" + strNowViewFile + "'","OrderID asc");            
              //当前访问的栏目名称
              string strTitle = dvNowMenu[0]["Title"].ToString();
              
              //读取所有属于该栏目的二级栏
              DataView dvSecond = ReadXmlDataView("HeadMenu.xml","Parents = '" + strTitle + "'","OrderID asc");          
 
              if(dvSecond.Count > 0)
              {                           
                   //输出二级栏目              
                   lblCode.Text += "<tr>";
                   lblCode.Text += "<td height='30' class='bgGray1'>";
 
                   for(int i=0; i < dvSecond.Count; i++)
                   {
                       //如果读出来的那条记录的链接地址是当前访问的文件,加粗当前访问的栏目名称并在前面加上·符号
                       if(dvSecond[i]["LinkUrl"].ToString().Trim().Equals(strNowViewFile))
                       {                           
                            lblCode.Text += "&nbsp;&nbsp;·<a href='" + dvSecond[i]["LinkUrl"].ToString().Trim() + "'>";
                            lblCode.Text += "<strong>" + dvSecond[i]["Title"].ToString().Trim() + "</strong>";
                            lblCode.Text += "</a>";
                            
                            //改变当前位置值,重新显示一级栏目的方法已经显示了当前的一级栏目位置,这里加上当前所在的二级栏目的位置                                                  
                            lblPosition.Text += " >> <a href='" + dvSecond[i]["LinkUrl"].ToString().Trim() + "'>" + strTitle + "</a>";                          
                            //到这里当前位置的表格显示已完成,刚好和重新显示一级栏目方法里的当前位置的表格代码接起来
                            lblPosition.Text += "</span></td></tr></table>";
                       }
                       else
                       {                           
                            lblCode.Text += "&nbsp;&nbsp;<a href='" + dvSecond[i]["LinkUrl"].ToString().Trim() + "'>";
                            lblCode.Text += dvSecond[i]["Title"].ToString().Trim();
                            lblCode.Text += "</a>";
                       }
                   }
                   lblCode.Text += "</td>";
                   lblCode.Text += "</tr>";
                   lblCode.Text += "</table>";      
              }
     } 

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

相关文章

关注我们

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