2012-06-27 4 views
0

기본적으로 그리드보기의 필터링 옵션을 구현하고 열 이름과 해당 열에 사용할 수있는 필터링 값이 포함 된 확인란 목록이 포함 된 드롭 다운 목록이 있습니다. 다른 열을 선택할 때마다 해당 열의 필터링 값을 확인란 목록에로드해야합니다. 문제는 드롭 다운 목록에서 열을 변경하면 체크리스트에 대한 이벤트가 발생하고 응용 프로그램이 충돌한다는 것입니다.DropdownList의 선택을 변경하면 CheckBoxList의 OnSelectedIndexChanged 이벤트가 발생합니다.

내 컨트롤은 다음과 같이 정의된다 :

나는 다음과 같은 코드가 코드 숨김 파일에서
<div class="LeftAligned"> 
    <asp:Label ID="FilterLabel" runat="server" Text="Filter by:" /> 
    <asp:DropDownList runat="server" ID="FilterReviewsDropDownList" AutoPostBack="true" OnSelectedIndexChanged="FilterReviewsDropDownList_SelectedIndexChanged" /> 
    <asp:ImageButton ID="FilterReviewsButton" runat="server" ImageUrl="~/images/filter.png" AlternateText="VALUE" CssClass="filter_button" OnClick="FilterReviewsButton_Click" /> 
    <div onmouseout="javascript:bMouseOver=false;" onmouseover="javascript:bMouseOver=true;" class="filter_div"> 
      <asp:CheckBoxList AutoPostBack="true" ID="FilterReviewsCheckBoxList" ClientIDMode="Static" runat="server" CssClass="filter_checklist collapsed" 
      OnSelectedIndexChanged="FilterReviewsCheckBoxList_Selected"> 
      </asp:CheckBoxList> 
    </div> 
    <%--asp:Button runat="server" ID="ApplyFilterButton" Text="Apply Filter" OnClick="ApplyFilterButton_Click"/> 
    <asp:Button runat="server" ID="ClearFilterButton" Text="Clear Filter" OnClick="ClearFilterButton_Click"/--%> 
</div> 

다음과 같은 드롭 다운리스트로 (

protected void FilterReviewsButton_Click(object sender, EventArgs e) 
{ 
    FilterReviewsCheckBoxList.CssClass = "filter_checklist"; 
} 

protected void FilterReviewsDropDownList_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    LoadFilterCheckboxes(FilterReviewsDropDownList.SelectedIndex); 
} 

private void LoadFilterCheckboxes(int iColumn) 
{ 
    SortedSet<string> oItems = new SortedSet<string>(); 

    for (int i = 0; i < ReviewsGridView.Rows.Count; i++) 
    { 
     IEnumerable<Label> oLabels = ReviewsGridView.Rows[i].Cells[iColumn].Controls.OfType<Label>(); 
     string sValue = ""; 
     if (oLabels != null && oLabels.Count() > 0) 
     { 
      sValue = oLabels.First().Text; 
     } 
     else 
     { 
      sValue = ReviewsGridView.Rows[i].Cells[iColumn].Text; 
     } 
     if (!oItems.Contains(sValue)) 
      oItems.Add(sValue); 
    } 

    FilterReviewsCheckBoxList.Items.Clear(); 
    FilterReviewsCheckBoxList.Items.Add("All"); 
    FilterReviewsCheckBoxList.Items[0].Selected = true; 
    foreach (string sItem in oItems) 
    { 
     FilterReviewsCheckBoxList.Items.Add(sItem); 
     FilterReviewsCheckBoxList.Items[FilterReviewsCheckBoxList.Items.Count - 1].Selected = true; 
    } 
} 

protected void FilterReviewsCheckBoxList_Selected(object sender, EventArgs e) 
{ 
    string sResult = Request.Form["__EVENTTARGET"]; 
    if (string.IsNullOrEmpty(sResult)) 
    { 
     FilterReviewsCheckBoxList.Items[0].Selected = true; //weird bug fix... 
     return; 
    } 

    string[] sCheckedBox = sResult.Split('$'); 
    //get the index of the item that was checked/unchecked 
    int i = int.Parse(sCheckedBox[sCheckedBox.Length - 1].Split('_')[1]); 
    if (i == 0) 
    { 
     if (FilterReviewsCheckBoxList.Items[i].Selected == true) 
     { 
      for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++) 
       FilterReviewsCheckBoxList.Items[j].Selected = true; 
     } 
     else 
     { 
      for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++) 
       FilterReviewsCheckBoxList.Items[j].Selected = false; 
     } 
    } 
    else 
    { 
     if (FilterReviewsCheckBoxList.Items[i].Selected == false) 
     { 
      FilterReviewsCheckBoxList.Items[0].Selected = false; 
     } 
     else 
     { 
      //if (oFirstTable != null) 
      //{ 
      // oTable = oFirstTable; 
      // oView = oTable.DefaultView; 
      //} 
      bool bAllChecked = true; 
      for (int j = 1; j < FilterReviewsCheckBoxList.Items.Count; j++) 
      { 
       if (FilterReviewsCheckBoxList.Items[j].Selected == false) 
       { 
        bAllChecked = false; 
        break; 
       } 
      } 
      if (bAllChecked) 
       FilterReviewsCheckBoxList.Items[0].Selected = true; 
     } 
    } 
} 

을 FilterReviewsCheckBoxList_Selected 왜 어떤 생각이 호출됩니다 보낸 사람 인수) 드롭 다운 목록을 변경할 때?

답변

0

동일한 문제가 발생할 수있는 사용자에게는 그리드보기가 엔터티 데이터 원본에 정적으로 바인딩되지 않도록 수정해야합니다. 대신 페이지로드 이벤트에서 그리드를 동적으로 바인딩하십시오.