![]() |
Checkboxes in a ListView losing checked attribute on postback
I have a user control that contains a ListtView control which contains
checkboxes in the item template. In the listview ItemDataBound event I use FindControl to get the checkbox, set some attributes and everything's fine. When the page posts back I'm losing the checked attribute...in other words all the checkboxes are unchecked - except the one's that are disabled. Nothing else is wrong with any of the other controls in this particular user control. Code snip: protected void ListViewItemRates_ItemDataBound(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.DataItem) { ListViewDataItem listViewDataItem = e.Item as ListViewDataItem; ItemRatesWrapper itemRateWrapper = listViewDataItem.DataItem as ItemRatesWrapper; CheckBox checkBoxPolicy = listViewDataItem.FindControl("CheckBoxPolicy") as CheckBox; checkBoxPolicy.ID = String.Format("{0}_{1}_{2}", "CheckBoxPolicy", SuitcaseItemIDCurrent, itemRateWrapper.PolicyKey); checkBoxPolicy.Checked = itemRateWrapper.IsSelected; checkBoxPolicy.Text = checkBoxPolicy.ToolTip = itemRateWrapper.Description.ToString(); checkBoxPolicy.Enabled = _canEditItemRates ? itemRateWrapper.GuestSelectable : false; if (checkBoxPolicy.Enabled) { checkBoxPolicy.ToolTip = (itemRateWrapper.IsSelected ? "Remove " : "Add ") + checkBoxPolicy.Text; checkBoxPolicy.Attributes.Add("style", "color:#07447B;cursor:pointer;"); } else { checkBoxPolicy.Attributes.Add("style", "color:#07447B;cursor:default;"); } Thanks in advance, Tom ASP.NET 3.5 |
| All times are GMT. The time now is 07:15 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.