I've been breaking my head on this one for a day now. But I just don't see it.
I have a checkboxlist named cblRounds which is
<asp:CheckBoxList ID="cblRondes" runat="server">
</asp:CheckBoxList>
Also to note, EnableViewstate is set to true.
In my code behind, in the page_Load i fill de list like this:
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()));
}
}
Then I click a button where I check the checkstate of the checkboxes
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));
}
}
}
}
Everything works correct except that the if (item.Selected) always returns false.
Also I have
<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>
The Datepicker returns a date I use to filter my collection. So when I press the searchbutton, I get "new" checkboxes in my checkboxlist. This is why I DON'T have the Fillcheckboxlist inside the if(!IsPostBack) else I get no checkboxes on a new search.
I've been searching for an answer on this and tried several things but none seem to work. Any ideas are appreciated.