当前位置:编程学习 > C#/ASP.NET >>

怎样获取datalist中checkbox被选中的个数

 <asp:DataList ID="DataList1" runat="server" Width="100%" 
            onitemcommand="DataList1_ItemCommand">
            <ItemTemplate>
                <table style="width:100%;">
                    <tr>
                        <td width="5%">
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("AdvertisementId") %>' 
                                Visible="False" Width="5%"></asp:Label>
                        </td>
                        <td width="15%">
                            <asp:CheckBox ID="CheckBox1" runat="server" Text="首页显示" />                        </td>
                        <td align="center" width="50%">
                           <a href ='AdvertShow.aspx?id=<%#Eval("AdvertisementId") %>'><%#Eval("AdvertisementTitle")%></a>
                        </td>
                        <td width="10%">
                            <asp:Button ID="Button1" runat="server" Text="编辑" CommandName="edit" />
                        </td>
                        <td>
                            <asp:Button ID="Button2" runat="server" Text="删除" CommandName="delete" />
                        </td>
                        <td>
                             </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList> --------------------编程问答-------------------- --------------------编程问答-------------------- int i=0;
foreach(DataListItem intem in DataList1.Items)
{
 CheckBox chk=item.FindControls("CheckBox1") as CheckBox ;
 if(chk.Checked){i++;}
} --------------------编程问答-------------------- 这么有玩过呢 看看 --------------------编程问答-------------------- int i=0;
foreach(DataListItem item_temp in DataList1.Items)
{
 if(item_temp.ItemType == ListItemType .Item || 
item_temp.ItemType == ListItemType .AlternatingItem )
 {
  CheckBox chk=item_temp.FindControls("CheckBox1") as CheckBox ;
  if(chk.Checked){i++;}

 }
} --------------------编程问答-------------------- 楼上正解!!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,