动态生成菜单

在下试过用DataList做出这种效果,不知道合不合你的要求啊?  
   
  从数据库中读取,形成一张DataTable  
  (其中"url"=你的链接(即aspx页面的文件名),"menu"=菜单文本,)  
   
  然后把数据源绑定到DataLsit,在aspx文件中这么写  
   
  <ItemTemplate>  
   
  <A     style="FONT:   menu;"   href='<%#   Global.m_sGetApplicationPath(Request)%>/<%#     DataBinder.Eval(Container.DataItem,   "url")   %>   '>  
  <%#     DataBinder.Eval(Container.DataItem,   "menu")   %></A>  
  </ItemTemplate>  
   
  在Global中写上这么一段函数:(用来返回当前的根路径)  
  Global.m_sGetApplicationPath(Request)  
  public   static   string   m_sGetApplicationPath(HttpRequest   request)    
  {  
  string   path   =   string.Empty;  
  try    
  {  
  if(request.ApplicationPath   !=   "/")  
  path   =   request.ApplicationPath;  
  }  
  catch   (Exception   e)  
  {  
                            throw   e;  
  }  
  return   path;  
  }   
   

你可能感兴趣的:(动态)