Checkboxes in a ListView losing checked attribute on postback

T

tom

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top