C# 中 FindControl 方法及使用
生活随笔
收集整理的這篇文章主要介紹了
C# 中 FindControl 方法及使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
FindControl 的使用方法
FindControl (String? id):?在頁命名容器中搜索帶指定標識符的服務器控件。(有點類似javascript中的getElementById(string))
?
今天做了一個打印的報表 ,要求在指定位置顯示列表中某字段的內容,開始時先查詢出數據列表再每個進行判斷然后賦值,太麻煩太啰嗦,現在知道了?FindControl 方法 用這個方法覺得比之前高級多了
后臺代碼
projectReviewCommentTable = municipalProjectBLL.GetCommentDTByProject(UserInfo, (string)this.ViewState["entityId"]);foreach (DataRow dr in projectReviewCommentTable.Rows){Label labelReviewer = FindControl("lblCertificateReviewer_" + dr[MunicipalProjectReviewCommentTable.FieldSpecialtyCode]) as Label;if (labelReviewer != null){labelReviewer.Text = dr[MunicipalProjectReviewCommentTable.FieldReviewer].ToString(); }Label labelChecker = FindControl("lblCertificateChecker_" + dr[MunicipalProjectReviewCommentTable.FieldSpecialtyCode]) as Label;if (labelChecker != null){labelChecker.Text = dr[MunicipalProjectReviewCommentTable.FieldChecker].ToString(); } }
?
需要頁面控件配合
<div class="Textbox6"><%--道路審查人--%><asp:Label ID="lblCertificateReviewer_LW" runat="server"></asp:Label></div><div class="Textbox10"><%--道路校審人--%><asp:Label ID="lblCertificateChecker_LW" runat="server"></asp:Label></div><div class="Textbox7"><%--橋梁隧道 審查人--%><asp:Label ID="lblCertificateReviewer_SD" runat="server"></asp:Label></div><div class="Textbox11"><%--橋梁隧道 校審人--%><asp:Label ID="lblCertificateChecker_SD" runat="server"></asp:Label></div><div class="Textbox15"><%--給排水 審查人--%><asp:Label ID="lblCertificateReviewer_JS" runat="server"></asp:Label><asp:Label ID="lblCertificateReviewer_PS" runat="server"></asp:Label></div><div class="Textbox16"><%--給排水 校審人--%><asp:Label ID="lblCertificateChecker_JS" runat="server"></asp:Label><asp:Label ID="lblCertificateChecker_PS" runat="server"></asp:Label></div><div class="Textbox5"><%--環境 審查人--%><asp:Label ID="lblCertificateReviewer_HJ" runat="server"></asp:Label></div><div class="Textbox9"><%--環境 校審人--%><asp:Label ID="lblCertificateChecker_HJ" runat="server"></asp:Label></div><div class="Textbox8"><%--燃氣 熱力 審查人--%><asp:Label ID="lblCertificateReviewer_RQ" runat="server"></asp:Label><asp:Label ID="lblCertificateReviewer_RL" runat="server"></asp:Label></div><div class="Textbox12"><%--燃氣 熱力 校審人--%><asp:Label ID="lblCertificateChecker_RQ" runat="server"></asp:Label><asp:Label ID="lblCertificateChecker_RL" runat="server"></asp:Label></div>?
轉載于:https://www.cnblogs.com/Tanghongchang/p/10607935.html
總結
以上是生活随笔為你收集整理的C# 中 FindControl 方法及使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分享一个windows下检测硬件信息的b
- 下一篇: 涡街流量计频率与流量的计算公式?