关于查找使用了母版页的内容页中的控件在这篇文章的评论里面我已经贴出来的,
http://thcjp.cnblogs.com/archive/2006/07/08/446076.html
下面是我浪费了至少4个小时才想出来的东西,其实最主要问题也是出在页的执行顺序上我弄错了,才会浪费那么久时间,郁闷!
http://thcjp.cnblogs.com/archive/2006/07/08/446076.html
下面是我浪费了至少4个小时才想出来的东西,其实最主要问题也是出在页的执行顺序上我弄错了,才会浪费那么久时间,郁闷!
protected
void
Page_Load(
object
sender, EventArgs e)
{
Repeater rp = (Repeater)Page.Master.FindControl( " Repeater1 " ); // 找出Repeater控件出来是第一步
rp.DataSource = dhdat; // 如果是让前面页他自己绑定的话,下面就读不出来项数了,
rp.DataBind(); // 所以这里是很重要的
int coun = rp.Items.Count; // 得到Repeater的项数
for ( int i = 0 ; i < coun; i ++ ) // 循环所有项
{
HyperLink diqu = (HyperLink)rp.Items[i].FindControl( " HyperLink1 " );
// 找到HyperLink1这个控件,也就是我们要做导航的字
string aid = ((Label)rp.Items[i].FindControl( " Label1 " )).Text.ToString() ;
// 因为Repeater没有主键,至少我不知道,所以就多放一个Label存放ID,这里再出来
string url = " list.aspx?aid= " + aid + "" ;
// 因为这个URL会有多个条件,所以在这里构造URL
if (Request.QueryString[ " aid " ] == null )
{
diqu.NavigateUrl = url;
}
//
.具体那些判断,看也没意思,略了
}
}
{
Repeater rp = (Repeater)Page.Master.FindControl( " Repeater1 " ); // 找出Repeater控件出来是第一步
rp.DataSource = dhdat; // 如果是让前面页他自己绑定的话,下面就读不出来项数了,
rp.DataBind(); // 所以这里是很重要的
int coun = rp.Items.Count; // 得到Repeater的项数
for ( int i = 0 ; i < coun; i ++ ) // 循环所有项
{
HyperLink diqu = (HyperLink)rp.Items[i].FindControl( " HyperLink1 " );
// 找到HyperLink1这个控件,也就是我们要做导航的字
string aid = ((Label)rp.Items[i].FindControl( " Label1 " )).Text.ToString() ;
// 因为Repeater没有主键,至少我不知道,所以就多放一个Label存放ID,这里再出来
string url = " list.aspx?aid= " + aid + "" ;
// 因为这个URL会有多个条件,所以在这里构造URL
if (Request.QueryString[ " aid " ] == null )
{
diqu.NavigateUrl = url;
}
//

}
}