嵌套Datalist控件,如何找到里层Datalist内的控件?

((DataList)this.dlRptCategory.FindControl("dlRptGoods")).Items[i].FindControl("hlGoToBuy");

 

通过这句可以吗? 然后怎么将这个控件实例化为HyperLink类型的?


蝴蝶不菲
浏览 508回答 2
2回答

慕虎7371278

dlRptCategory.DataSource = 数据源;dlRptCategory.DataBind();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i < dlRptCategory.Items.Count; i++){&nbsp;&nbsp;&nbsp; // 获得内嵌的DataList&nbsp;&nbsp;&nbsp; DataList dlRptGoods= (DataList)dlRptCategory.Items[i].FindControl("dlRptGoods");&nbsp;&nbsp;&nbsp; // 绑定子模块&nbsp;&nbsp;&nbsp; dlRptGoods.DataSource =&nbsp;数据源;&nbsp;&nbsp;&nbsp; dlRptGoods.DataBind();&nbsp;&nbsp;&nbsp; for(int i=0; i<dlRptGoods.Items.Count; i++)&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dlRptGoods.Items[i].FindControl("hlGoToBuy")&nbsp;&nbsp;&nbsp; }}公式:((DataList)父.Items[i].FindControl("子id")).Items[i].FindControl("hlGoToBuy")你的错误是:父.FindControl ,应该是父.Items[i].FindControl

慕妹3242003

&nbsp;可以 .就是这么用啊。你这个是repeater是把..
打开App,查看更多内容
随时随地看视频慕课网APP