ASP.NET 2.0(C#)中使用webpart系列控件(4)

来源:互联网 发布:初级u3d程序员工资 编辑:程序博客网 时间:2024/06/01 11:36

ASP.NET 2.0(C#)中使用webpart系列控件(4)

1、往窗体中拖拉一个catlogzone控件,如下图所视。

   
     2、往该catlogzone控件区域中,再拖放三个Webpart系列的控件,分别是DeclarativeCatalogPart, PageCatalogPart, and ImportCatalogPart,如下图所示。其中,DeclarativeCatalogPart控件的作用是,显示目前页面上有哪些可以用的webpart控件;PageCatalogPart的作用是,可以让用户通过勾选的方式,选定将哪些控件添加转移到其他webpart区域中去。ImportCatalogPart则可以通过外部磁盘文件的方式,加载其他做好了的webpart部件。


     3、在RadioButtonList区域中,修改以下代码,增添一个catalog display的显示模式:
  
  <ASP:RadioButtonList ID="rblMode" runat="server" AutoPostBack="True">
  <asp:ListItem>Browse Display Mode</asp:ListItem>
  <asp:ListItem>Design Display Mode</asp:ListItem>
  <asp:ListItem>Catalog Display Mode</asp:ListItem>
  </asp:RadioButtonList>
  
    然后,在code-behind的代码中,将代码修改为如下:
  
  protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch(rblMode.SelectedIndex)
        {
    case 0 :
        {
        WebPartManager1.DisplayMode =WebPartManager.BrowseDisplayMode ;
       break ;
        }
      case 1 :
        WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
        break ;
      case 2 :
          WebPartManager1.DisplayMode = WebPartManager.CatalogDisplayMode;
          break;
        }

    }   
    4、在DeclarativeCatalogPart任务菜单上,点击右上角的智能感知按钮,然后选"edit templates"的链接,进入模版编辑状态,如下图: 
    

再往其中的webpartstemplate区域中拖拉一个google.ascx控件,如下图,这将允许用户在运行时,可以自由地往页面增加这样的google搜索控件。 
   
   5、然后修改代码如下:
  
  <ZoneTemplate>
  <asp:DeclarativeCatalogPart ID="DeclarativeCatalogPart1" runat="server">
   <WebPartsTemplate>
    <uc1:Google title="Google Search" ID="Google2" runat="server" />
   </WebPartsTemplate>
  </asp:DeclarativeCatalogPart>
  
    6、运行程序,可以看到,当选择catalog display mode时,会显示如下图所示的catalog zone,其中列出了当前可用的有哪些webpart控件,我们可以把这个google的控件加到其他的webpart区域,也可以尝试将已经存在的webpart控件关闭,然后在catalog zone区域中的控件列表中,把它们再加回到页面中去。    
  

 
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 中老年夜尿频繁怎么办 带状疮疹后期痒怎么办 阴茎上长珍珠疹怎么办 子宫大怎么办能变小吗 子宫前壁肌瘤5.4怎么办 7个月孕妇得疱疹怎么办 受风脸上起疙瘩怎么办 受风了起疙瘩怎么办 7个月宝宝肠炎怎么办 出水痘发烧39度怎么办 腰肌拉伤怎么办恢复快 过敏起大水泡了怎么办 身上长疱疹怎么办冶疗 刚怀孕长了疱疹怎么办 吃完饭恶心想吐怎么办 减肥药吃了心慌怎么办 吃多了恶心想吐怎么办 想吐怎么办最快最有效 想吐又吐不出来怎么办 3岁宝宝反胃呕吐怎么办 2岁宝宝反胃呕吐怎么办 突然恶心想吐是怎么办 孕4个月反胃呕吐怎么办 怀孕2月反应大怎么办 狗吐拉稀不吃饭怎么办 狗狗咳喘怎么办最有效 半永久纹眉失败怎么办 纹的眉毛太细了怎么办 眉毛颜色做深了怎么办 半永久眼线不掉怎么办 移植9天来月经怎么办 月经迟迟不来该怎么办 lol晋级赛输了怎么办 激素正常的多囊怎么办 右侧输卵管通而不畅怎么办 小该咳嗽老不好怎么办 孩子吓着了怎么办最快 2个月宝宝吓到了怎么办 3个月宝宝吓到了怎么办 宝宝吓着了发烧怎么办 好几个月不遗精怎么办