zoukankan      html  css  js  c++  java
  • [转载][教程]母版页里面查找Repeater内控件(自动编号),并构造URL

    转载:http://www.cnblogs.com/thcjp/archive/2006/07/20/455489.html

    关于查找使用了母版页的内容页中的控件在这篇文章的评论里面我已经贴出来的
    http://thcjp.cnblogs.com/archive/2006/07/08/446076.html

    原作者的话,引以为鉴
    (下面的代码是我浪费了至少4个小时才想出来的东西,其实最主要问题也是出在页的执行顺序上我弄错了,才会浪费那么久时间,郁闷!)

     1protected void Page_Load(object sender, EventArgs e)
     2    {
     3        Repeater rp = (Repeater)Page.Master.FindControl("Repeater1");//找出Repeater控件出来是第一步
     4        rp.DataSource = dhdat; //如果是让前面页他自己绑定的话,下面就读不出来项数了,       
     5        rp.DataBind();//所以这里是很重要的
     6        
     7        int coun = rp.Items.Count;//得到Repeater的项数
     8        for (int i = 0; i < coun; i++)//循环所有项
     9        {
    10            HyperLink diqu = (HyperLink)rp.Items[i].FindControl("HyperLink1");
    11            //找到HyperLink1这个控件,也就是我们要做导航的字
    12            string aid = ((Label)rp.Items[i].FindControl("Label1")).Text.ToString() ;
    13            //因为Repeater没有主键,至少我不知道,所以就多放一个Label存放ID,这里再出来
    14            string url="list.aspx?aid=" + aid + "";
    15            //因为这个URL会有多个条件,所以在这里构造URL
    16            if (Request.QueryString["aid"== null)
    17            {
    18                diqu.NavigateUrl = url;
    19            }

    20            //.具体那些判断,看也没意思,略了
    21        }

    22       
    23
    24       
    25    }

    26
  • 相关阅读:
    Handler使用入门 下载文件
    基于QT前端的mplayer播放器2
    HTTP协议详解(真的很经典)
    安装 gentoo minimal cd
    linux 分区方案
    MFC 中添加按钮和事件
    makefile 学习
    堆和栈
    paste命令使用
    cut用法
  • 原文地址:https://www.cnblogs.com/apiapia/p/657487.html
Copyright © 2011-2022 走看看