开发者

How to access a checkBox inside a repeater Header?

开发者 https://www.devze.com 2023-02-11 14:07 出处:网络
I have a repeater which has a checkBox in the headerTemplate <asp:Repeater ID=\"myRepeater\" runat=\"Server\">

I have a repeater which has a checkBox in the headerTemplate

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

I'm wanting to know how I 开发者_开发问答can get the value of that checkBox in the code behind. Any ideas?


Inside your ItemDataBound method call FindControl("checkboxID") and cast to 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;
    }
}

Or you could do this anytime:

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

精彩评论

暂无评论...
验证码 换一张
取 消