我需要访问我的转发器的标头模板中的一些复选框。
实际上它们不在它之中,并且在后面的代码中使用关键字" this"来访问它们。我无法改变所有代码,我必须保持相同的逻辑。问题是,如果我移动转发器标头内的复选框,我找不到使用"这个"。
我有这样的事情:
<div id="containerListNotify" style="padding-left: 5px;">
<asp:UpdatePanel ID="UpdatePanelRepListNotify" runat="server" UpdateMode="Conditional" ClientIDMode="Static">
<ContentTemplate>
<asp:HiddenField ID="iconsHiddenField" runat="server" ClientIDMode="Static" />
<asp:Repeater ID="repListNotify" runat="server" OnItemCommand="RepListNotify_ItemCommand"
OnItemDataBound="RepListNotify_ItemCreated">
<HeaderTemplate>
<table id="tableCentroMessaggi" class="table table-hover">
<thead>
<tr id="HeaderMessaggi">
<th>
<%--<asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' />--%>
<div class="dropdown">
<button onclick="openCloseDocFascDropdown()" class="dropbtn"><asp:Label runat="server" ID="docFascCol" Text='<%#this.getDocFascColText() %>' /><b class="caret"></b></button>
<div id="docFascDropdown" class="dropdown-content">
<ul>
<li>
<asp:CheckBox ID="IndexCheckDoc" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckProj" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
<li>
<asp:CheckBox ID="IndexCheckOther" CssClass="clickableLeftN" Checked="true" runat="server"
AutoPostBack="true" OnCheckedChanged="IndexCkbFilterObject_CheckedChanged" />
</li>
</ul>
</div>
</div>
</th>
<th>
重要的是我甚至需要在私有方法中访问它们,而不仅仅是在事件方法中。
我希望有一个解决方案。我想我可以使用&#34; FindControl&#34;。 此.aspx使用MasterPage。
提前致谢。
答案 0 :(得分:0)
如果你想访问另一个控件里面的控件,比如Repeater,GridView等,你将不得不使用FindControl和item / row索引。你访问它们的地方并不重要。
CheckBox IndexCheckDoc = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckDoc") as CheckBox;
CheckBox IndexCheckProj = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckProj") as CheckBox;
CheckBox IndexCheckOther = repListNotify.Controls[0].Controls[0].FindControl("IndexCheckOther") as CheckBox;