转载:http://www.cnblogs.com/thcjp/archive/2006/07/20/455489.html
关于查找使用了母版页的内容页中的控件在这篇文章的评论里面我已经贴出来的
http://thcjp.cnblogs.com/archive/2006/07/08/446076.html
原作者的话,引以为鉴
(下面的代码是我浪费了至少4个小时才想出来的东西,其实最主要问题也是出在页的执行顺序上我弄错了,才会浪费那么久时间,郁闷!)
1
protected 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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26
