我在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>
谢谢
答案 0 :(得分:1)
foreach (ListViewItem row in ListView2.Items)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox1");
if( cb != null)
{
if (cb.Checked == true)
{
//Some Stuf..
}
}
}