[ASP.NET笔记] 6.导航控件

                               1:Menu控件[菜单]
                               2:TreeView控件[树状]
                               3:SiteMapPath控件[网站路径]
                               4:MasterPage:母版页

                     Menu菜单控件
                     属性:
                      1)Item:用来设置菜单的项,还可以设置单击每一项时(NavigateUrl),进入的页面
                      2)Orientation:菜单的方向。
                      3)StaticEnableDefaultPopOutImage:是否三角箭头。
                      4)Font:设置菜单的字体
                      5)BorderStyle:设置菜单的边框样式。一般设为OutSet
                      6)DynamicMenuItemStyle:设置子菜单的样式  一般设为Groove
                      7)Target:用户单击了菜单项之后,用另外一个浏览器打开页面

                    TreeView控件:
                      属性:
                       1)Nodes:用来管理TreeView中各个节点。通过NavigateUrl设置对应的页面
                       2)NodeIndent:决定各父子节点之间的距离
                       3)SelectedNode:得到所选中的节点
                       4)this.TreeView1.SelectedNode.ChildNodes.Add(new TreeNode("天花板","值","导航"));
                             在选中的节点下面添加子节点:
                       5)添加节点:
                            DataTable dt = DataOper.RunHasResult("select * from 部门");
                            TreeNode root = new TreeNode("选择了部门");
                            this.TreeView2.Nodes.Add(root);
                            foreach (DataRow dr in dt.Rows)
                              {
                                 TreeNode tn=new TreeNode(dr[0].ToString(),dr[1].ToString());
                                 root.ChildNodes.Add(tn);                
                              }
                       5)删除选中的节点:
                           if (this.TreeView1.SelectedNode.Parent != null)
                                {
                                        this.TreeView1.SelectedNode.Parent.ChildNodes.Remove(this.TreeView1.SelectedNode);
                                }
                           else
                                {
                                    this.TreeView1.Nodes.Remove(this.TreeView1.SelectedNode);
                                }
                       6)如何得到单击节点的文本与值。在SelectedNodeChanged事件里写上代码
                           this.TreeView1.SelectedNode.Text或this.TreeView1.SelectedNode.Value
                       7)几种情况:                          
                          A)单击节点时,不弹出页面,直接去执行某些代码。此时,应该在
                             SelectedNodeChanged事件里写上代码
                              举例:让用户在商品类别表中选择一种类别,在同一个页面里面显示该种
                                    商品

                          B)单击节点时,弹出页面,但是不传递值。此时,应该在添加节点时,
                            直接指定NavigateUrl
        举例:让用户在框架左边,选择对应的模块名,又边出现对应的页面
                                                        
                          C)单击节点时,弹出页面,还要传递值。此时,应该在添加节点时,
                            直接指定NavigateUrl,和value
                                 this.TreeView2.Nodes.Add(root);
                                 foreach (DataRow dr in dt.Rows)
                                      {
                                        TreeNode tn = new TreeNode();
                                        tn.Text = dr[1].ToString();
                                        tn.Value = dr[0].ToString();
                                        tn.NavigateUrl = "default2.aspx?id=" + dr[0].ToString();
                                        root.ChildNodes.Add(tn);                
                                      }
        举例:
                                  让用户在商品类别表中选择一种类别,在另外一个页面里面显示该种
                                   商品

                           D)从数据库的树型表里面填充treeview
                              假设有表:
                               NodeId       ParentNode       NodeName           Url
                               10000          0                      浙江省          www.hubei.com
                               10001        10000                 东阳市
                               10002        10000                 义乌市
                               10003          0                      广东省
                               10004        10003                 广州市
                               10005        10003                 肇庆市           
 
                      SiteMapPath控件
                                步骤:
                                 1)创建站点地图文件SiteMap文件。是一个xml文件格式
                                   <?xml version="1.0" encoding="utf-8" ?>
      <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
         <siteMapNode url="" title=""  description="">
             <siteMapNode url="" title=""  description="" />
             <siteMapNode url="" title=""  description="" />
                </siteMapNode>
      </siteMap>
                                         Url:决定单击节点,所转到的页面
                                         Title:节点的标题
                                         Description:节点的描述说明
                                  2)直接拖拉多个SiteMapPath到每一个页面上,从第二个页面开始
                                    注意首页一般不用加SiteMapPath
                                  4)设置各个级别的路径分割符

                                 举例:
                                   论坛首页--->计算机技术--->编程技术--->网络编程
                            
                      MasterPage:母版页
                            能够固定某一个页面的区域,而使其它区域发生改变.
                            能够发生改变的页是内容页,不能发生改变的页是母版页
                            步骤:
                            1)创建一个母版页,并加入ContentPlaceHolder控件,用来装内容页
                            2)使用母版页。在新建网页面,勾选使用母版页,然后再选择一个母版页
       3)一个母版页面里面可以有多个ContentPlaceHolder控件
                            4)很显然,内容页会随着母版页的变化,而发生变化。所以有时内容页希望        
                              有几种情况:
                                1)同一个页面里面,内容页向母版页里面得到传递的数据                             
                                   从母版页里面得到获得传递的数据
                                   方法1:通过Url查询字符串
                                    母版页:放入菜单,商品--->水果类,服饰类,家用类
                                    内容页:放入GridView,内容页根据母版页所选择的商品类型不一样
                                    而发生对应的改变
                                   方法2:通过Master对像
                                    比如:Master.FindControl("DropDownList1") as DropDownList).SelectedItem.Value;
                                    举例:
                                    母版页:放入一个下拉框,下拉框里面填充部门名称,从数据库里面获取
                                    内容页:放入GridView,内容页根据母版页所选择的部门得到该部门的职工                                 
                                2)不同页面之间,内容页的传值
                                    源内容页面:Server.Transver("目的内容页");
                                    目的内容页:((TextBox)PreviousPage.Form.FindControl("ContentPlaceHolder2").FindControl("txtUser")).Text;
                                                                          //这里是源页面的ContentPlaceHolderID="ContentPlaceHolder2",而不是ID="Content1"
                                    源内容页面:  内容页 用户名密码
                                    目的内容页面:接受内容页的用户名或显示欢迎信息

posted @ 2009-12-02 22:06  吴庆阳  阅读(532)  评论(0编辑  收藏  举报