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");
精彩评论