神龙之初

导航

FindControl的作用。

FindControl为我们提供了可以在C#文件中动态控制DataGrid,DataList中ItemTemplate里面的控件,甚至可是实现控件中嵌套一个控件。用好FindControl可以省去在aspx文件中使用比如<%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%>这样来读取数据的麻烦。
先申明控件,然后使用,很是方便。
HyperLink hy2 = (HyperLink)this.DataGrid1.Items[i].FindControl("Title"); 
      hy2.NavigateUrl = dt.Rows[i]["ProjectUrl"].ToString();
      hy2.Text = dt.Rows[i]["ProjectTitle"].ToString();
      Label lb6 = (Label)this.DataGrid1.Items[i].FindControl("Desc");
      Label lb7 = (Label)this.DataGrid1.Items[i].FindControl("Induc");
      Label lb8 = (Label)this.DataGrid1.Items[i].FindControl("SUsed");
      lb6.Text = dt.Rows[i]["ProjectDescription"].ToString();
      lb7.Text = dt.Rows[i]["Industry"].ToString();
      lb8.Text = dt.Rows[i]["UsedProduct"].ToString(); 
      
      System.Web.UI.WebControls.Image images = (System.Web.UI.WebControls.Image)this.DataGrid1.Items[i].FindControl("Image1");
      images.ImageUrl = dt.Rows[i]["CasePicture"].ToString();
<%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%><%# GetUpdateToProductName((int)(((DataRowView)Container.DataItem)["updateToProductID"]))%>

posted on 2004-12-13 17:45  David  阅读(1371)  评论(1编辑  收藏  举报