如何在列表视图asp.net C#中控制复选框Situation

本文关键字:控制 复选框 Situation net asp 列表 视图 | 更新日期: 2023-09-27 18:22:10

我是控制复选框是否在GridView中选中,如下面的中所示

foreach (GridViewRow row in GridView2.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
                if (cb.Checked == true)
                {
                    if (cb != null && cb.Checked)
                    {
                           //Some Stuf..
                    }
                }
              }

但我找不到如何控制列表视图中的复选框的方法,因为Listview不像网格视图中那样有扩展名"Row",你能帮我吗?

我的listview代码写在下面的中

<asp:ListView ID="ListView2" runat="server">
             <LayoutTemplate>
            <ul>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server" />
            </ul>
        </LayoutTemplate>
        <ItemTemplate>
            <li>
                         <asp:CheckBox ID="CheckBox1" runat="server" />
                        <b>City: </b><span class="city"><%# Eval("eeee") %></span><br />
                        <b>Postal Code: </b><span class="postal"><%# Eval("dddd") %></span><br />
                        <b>Country: </b><span class="country"><%# Eval("cccc")%></span><br />
                        <b>Phone: </b><span class="phone"><%# Eval("bbbb")%></span><br />
                        <b>Fax: </b><span class="fax"><%# Eval("aaaa")%></span><br />
            </li>

        </ItemTemplate>
            <LayoutTemplate>
                <div id="itemPlaceholderContainer" runat="server" style="font-family: Verdana, Arial, Helvetica, sans-serif;">
                    <span runat="server" id="itemPlaceholder" />
                </div>
                <div style="text-align: center;background-color: #FFCC66;font-family: Verdana, Arial, Helvetica, sans-serif;color: #333333;">
                    <asp:DataPager ID="DataPager1" runat="server">
                        <Fields>
                            <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                            <asp:NumericPagerField />
                            <asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
                        </Fields>
                    </asp:DataPager>
                </div>
            </LayoutTemplate>
        <EmptyDataTemplate>
            Sonuç Bulunamadı
        </EmptyDataTemplate>
        </asp:ListView>

感谢

如何在列表视图asp.net C#中控制复选框Situation

foreach (ListViewItem row in ListView2.Items)
    {            
        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if( cb != null)
            {
                if (cb.Checked == true)
                {
                       //Some Stuf..
                }
            }
    }