我有一個ListView和一些複選框。但如果我想知道是否選中了複選框,它總是假(即使我檢查了它)。ASP.NET CheckBox.Checked在ListView中始終爲false
這是我的ListView
<asp:ListView ID="lvCompanies" runat="server" DataKeyNames="id" onitemdatabound="lvCompanies_ItemDataBound">
<LayoutTemplate><ul><asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder></ul></LayoutTemplate>
<ItemTemplate>
<li>
<asp:CheckBox ID="cbCompany" CssClass="checkbox company-checkbox" runat="server" />
<%# Eval("Name") %>
</li>
</ItemTemplate>
</asp:ListView>
的代碼這是我試圖讓選中的複選框
public List<Company> getSelectedItems()
{
foreach (ListViewDataItem dataItem in lvCompanies.Items)
{
bool isChecked = ((CheckBox)dataItem.FindControl("cbCompany")).Checked;
}
}
你有任何想法,爲什麼我的複選框總是選中=假?
非常感謝,
文森特
哪種方法/事件處理中是你調用方法getSelectedItems界lvCompanies? – 2012-02-17 13:46:20