【发布时间】:2012-12-02 22:26:48
【问题描述】:
我已经为这个问题困扰了一天。 但我就是没看到。
我有一个名为 cblRounds 的复选框列表
<asp:CheckBoxList ID="cblRondes" runat="server">
</asp:CheckBoxList>
还要注意,EnableViewstate 设置为 true。
在我后面的代码中,在 page_Load 我这样填写列表:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dpPrintRounds.FieldValue = DateTime.Now.AddDays(1);
}
FillCheckBoxList();
}
private void FillCheckBoxList()
{
tourCollectie = new LogisticsTourCollection();
RelationCollection rc = new RelationCollection(LogisticsItemEntity.Relations.LogisticsItemSpecsEntityUsingSeqSpecs);
rc.Add(LogisticsItemSpecsEntity.Relations.LocationEntityUsingSeqLocationDelivery);
rc.Add(LocationEntity.Relations.LocationLogisticsTourEntityUsingSeqLocation);
rc.Add(LocationLogisticsTourEntity.Relations.LogisticsTourEntityUsingSeqLogisticsTour);
PredicateExpression pe = new PredicateExpression(LogisticsItemSpecsFields.RequiredDeliveryDate == dpPrintRounds.FieldValue);
pe.Add(LogisticsItemFields.DeliveryNumber != DBNull.Value);
tourCollectie.GetMulti(pe, rc);
cblRondes.Items.Clear();
foreach (LogisticsTourEntity tour in tourCollectie)
{
cblRondes.Items.Add(new ListItem(tour.Name, tour.SeqLogisticsTour.ToString()));
}
}
然后我点击一个按钮来检查复选框的检查状态
protected void btnPrintHeaders_Click(object sender, EventArgs e)
{
PrintRounds();
}
private void PrintRounds()
{
if (dpPrintRounds.Date_Selected.HasValue)
{
Dictionary<string, string> rondes = new Dictionary<string, string>();
foreach (ListItem item in cblRounds.Items)
{
if (item.Selected)
{
rondes.Add(item.Value, GetDeliveryNumberFromRonde(item.Value));
}
}
}
}
一切正常,除了 if (item.Selected) 总是返回 false。
我也有
<td>
<rm:DatePicker ID="dpPrintRounds" runat="server" />
</td>
<td>
<asp:Button ID="btnSearch" runat="server" Visible="true"
onclick="btnSearch_Click" />
<%--<asp:Literal ID="litLogisticsRoundName" runat="server" />:--%>
</td>
Datepicker 返回一个我用来过滤收藏的日期。 因此,当我按下搜索按钮时,我的复选框列表中会出现“新”复选框。 这就是为什么我在 if(!IsPostBack) 中没有 Fillcheckboxlist 的原因,否则我在新搜索中没有复选框。
我一直在寻找这个问题的答案并尝试了几件事,但似乎都没有奏效。 任何想法都表示赞赏。
【问题讨论】:
标签: c# asp.net checkbox checkboxlist