2011-02-11 3 views
0

C#とVB.NETの両方の提案をしたいと思います。ListViewでチェックされたすべてのCheckBoxをカウントしてページングします

私は、次のようなDataPagerを持つ単純なリストビューを持っている:

<asp:ListView ID="lvStudent" runat="server"> 
    <LayoutTemplate> 
     <table id="TimeSheet" cellspacing="1" class="tablesorter"> 
      <thead> 
       <tr> 

       <th> 
       ID# 
       </th> 

        <th> 
         <asp:LinkButton ID="lnkByName" runat="server">Name</asp:LinkButton> 
        </th> 
        <th> 
         <asp:CheckBox ID="selectAll" runat="server" OnClick="selectAll(this)"/> 
        </th>   

       </tr> 
      </thead> 
      <tbody> 
       <tr id="itemPlaceholder" runat="server" /> 
      </tbody> 
     </table> 
    </LayoutTemplate> 
    <ItemTemplate> 
     <tr> 
     <td class="id"> 
     <%#Eval("Id")%> 
     </td> 

      <td> 
       <%#Eval("Name")%> 
       <asp:HiddenField ID="hfId" runat="server" Value='<%#Eval("Id")%>' /> 
      </td> 

      <td> 
       <asp:CheckBox ID="cbSelected" runat="server"/> 
       </td>    
    </ItemTemplate> 
</asp:ListView> 


<div> 
    <asp:DataPager ID="dpReport" runat="server" 
    PagedControlID="lvStudent" PageSize="20"> 
    <Fields> 
     <asp:NextPreviousPagerField ShowFirstPageButton="True" ShowNextPageButton="False" /> 
     <asp:NumericPagerField NumericButtonCssClass="dpTimeSheet" ButtonCount="50" ButtonType="Link" /> 
     <asp:NextPreviousPagerField ShowLastPageButton="True" ShowPreviousPageButton="False" /> 
    </Fields> 
</asp:DataPager> 
</div> 

ページングは​​ありません場合、私はこのようなすべてのチェックをチェックボックス得ることができます。

Public Function CountSelectedCheckBox() As Integer 

    Dim count As Integer = 0 
    Dim s As String 

    For Each i As ListViewDataItem In lvStudent.Items 

     Dim cb = CType(i.FindControl("cbSelected"), CheckBox) 

     If cb.Checked Then 
      count = count + 1 
     End If 
    Next 

    Return count 

End Function 

をしかし、どのように私はすべて数えるんページングを持つListViewのチェックボックスをオンにしましたか?

答えて

0

私はあなたの機能性のようなものを実装しました。 セッションまたはViewStateでcheckedIdsを保存してみます。 もちろんリクエストごとにcheckedIdsを更新する必要があります。

関連する問題