C# 如何访问转发器标题内的复选框?

C# 如何访问转发器标题内的复选框?,c#,asp.net,checkbox,C#,Asp.net,Checkbox,我有一个中继器,在headerTemplate中有一个复选框 <asp:Repeater ID="myRepeater" runat="Server"> <HeaderTemplate> <table> <tr> <th> <asp:CheckBox ID="selectAllCheckBox" runat="Server" AutoPostBack="true>

我有一个中继器,在headerTemplate中有一个复选框

<asp:Repeater ID="myRepeater" runat="Server">
  <HeaderTemplate>
    <table>
      <tr>
        <th>
          <asp:CheckBox ID="selectAllCheckBox" runat="Server" AutoPostBack="true>
                         .
                         .
                         .


在ItemDataBound方法中,调用FindControl(“checkboxID”)并强制转换为Checkbox

void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) {
    if (e.Item.ItemType == ListItemType.Header) {
        CheckBox cb = (CheckBox)e.Item.FindControl("selectAllCheckBox");
        bool isChecked = cb.Checked;
    }
}
或者您可以随时这样做:

CheckBox cb = (CheckBox)myRepeater.Controls.OfType<RepeaterItem>().Single(ri => ri.ItemType == ListItemType.Header).FindControl("selectAllCheckBox");
CheckBox cb=(CheckBox)myRepeater.Controls.OfType().Single(ri=>ri.ItemType==ListItemType.Header).FindControl(“selectAllCheckBox”);

第二个选项似乎不起作用。找不到复选框抱歉,第二种方法不起作用-我正在删除它。如果要获取页眉或页脚行中的内容,必须使用ItemDataBound事件(我的第一种方法)-请参阅