1

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

1 Answer 1

2
foreach (ListViewItem row in ListView2.Items)
    {            
        CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
            if( cb != null)
            {
                if (cb.Checked == true)
                {
                       //Some Stuf..
                }
            }
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you that's what i'm looking for =) . It's very very helpfull to me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.