惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
Y
Y Combinator Blog
I
InfoQ
美团技术团队
罗磊的独立博客
B
Blog RSS Feed
GbyAI
GbyAI
小众软件
小众软件
IT之家
IT之家
Engineering at Meta
Engineering at Meta
Blog — PlanetScale
Blog — PlanetScale
V
V2EX
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Jina AI
Jina AI
MyScale Blog
MyScale Blog
博客园 - 聂微东
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss

博客园 - 豆丁不想长大

CheckBoxList与表的操作 - 豆丁不想长大 - 博客园 判断用户浏览器类型的代码 - 豆丁不想长大 - 博客园 GridView的RowdataBound事件 后台代码创建Table javascript循环判断Radio是否选中 - 豆丁不想长大 - 博客园 不错的韩剧 19根烟忘却你的理由 28句朴素的道白 Web.config详解 - 豆丁不想长大 - 博客园 忘记密码发送邮件提醒的代码 弹出对话框后转到下一页的代码 后台编写返回上一页的代码 Gridview中的DataKeys問題 ASP.net2.0学习资料汇总 星巴克咖啡价格 ASP.NET 常用代码 MessageBox的CS文件中的写法 Split的用法 关于DDL控件提交后刷新问题
FindControl的作用
豆丁不想长大 · 2007-01-03 · via 博客园 - 豆丁不想长大

FindControl为我们提供了可以在C#文件中动态控制DataGrid,DataList中ItemTemplate里面的控件,甚至可是实现控件中嵌套一个控件。用好FindControl可以省去在aspx文件中使用比如<%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%>这样来读取数据的麻烦。
先申明控件,然后使用,很是方便。 

<%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%>

 1 HyperLink hy2 = (HyperLink)this.DataGrid1.Items[i].FindControl("Title");  
 2       hy2.NavigateUrl = dt.Rows[i]["ProjectUrl"].ToString(); 
 3       hy2.Text = dt.Rows[i]["ProjectTitle"].ToString(); 
 4       Label lb6 = (Label)this.DataGrid1.Items[i].FindControl("Desc"); 
 5       Label lb7 = (Label)this.DataGrid1.Items[i].FindControl("Induc"); 
 6       Label lb8 = (Label)this.DataGrid1.Items[i].FindControl("SUsed"); 
 7       lb6.Text = dt.Rows[i]["ProjectDescription"].ToString(); 
 8       lb7.Text = dt.Rows[i]["Industry"].ToString(); 
 9       lb8.Text = dt.Rows[i]["UsedProduct"].ToString();  
10        
11       System.Web.UI.WebControls.Image images = (System.Web.UI.WebControls.Image)this.DataGrid1.Items[i].FindControl("Image1"); 
12       images.ImageUrl = dt.Rows[i]["CasePicture"].ToString(); 
13 

<%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%>