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

推荐订阅源

OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
有赞技术团队
有赞技术团队
H
Help Net Security
V
Visual Studio Blog
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 司徒正美
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
N
Netflix TechBlog - Medium
罗磊的独立博客
The GitHub Blog
The GitHub Blog
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements

博客园 - 豆丁不想长大

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"]))%>