Reputation: 556
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
Upvotes: 1
Views: 2070
Reputation: 7490
foreach (ListViewItem row in ListView2.Items)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
if( cb != null)
{
if (cb.Checked == true)
{
//Some Stuf..
}
}
}
Upvotes: 2