2011-02-18 2 views
2

나는 내가 뒤에있는 코드에서 그 체크 박스의 값을 얻을 수있는 방법을 알고 싶어 해요는 HeaderTemplate리피터 헤더 안의 checkBox에 액세스하는 방법은 무엇입니까?

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

의 체크 박스가있는 중계기가 있습니다. 어떤 아이디어?

답변

2
void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) { 
    if (e.Item.ItemType == ListItemType.Header) { 
     CheckBox cb = (CheckBox)e.Item.FindControl("selectAllCheckBox"); 
     bool isChecked = cb.Checked; 
    } 
} 

확인란

로하여 ItemDataBound 메소드 호출의 FindControl ("checkboxID")와 캐스트 내부

또는 당신이 언제 할 수있는 : 두 번째 옵션이 작동하지 않는 것

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

것을. checkBox를 찾을 수 없습니다 –

+0

죄송합니다. 두 번째 방법은 작동하지 않습니다. 삭제하고 있습니다. 머리말이나 꼬리말 행에 물건을 집어 넣고 싶다면 ItemDataBound 이벤트 (첫 번째 방법)를 사용해야합니다. - http://stackoverflow.com/questions/495597/why-is-the-footer-item-not을 참조하십시오. -included-in-repeater-items –

+0

언제든지 작동해야하는 최신 편집 내용을 수정했습니다. –

관련 문제