简体   繁体   中英

How to control checkbox Situation in List View asp.net C#

I'm control check box checked or not in GridView like in the below

foreach (GridViewRow row in GridView2.Rows)
            {
                CheckBox cb = (CheckBox)row.FindControl("CheckBox1");

                if (cb.Checked == true)
                {
                    if (cb != null && cb.Checked)
                    {
                           //Some Stuf..

                    }
                }
              }

But i can't find the way how to control check box in list view Because Listview doesn't have extension "Row" like in the grid view could you help me about it?

My listview code written in the below

<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>

Thank you

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM