Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Checkboxes in a ListView losing checked attribute on postback (http://www.velocityreviews.com/forums/t781092-checkboxes-in-a-listview-losing-checked-attribute-on-postback.html)

tom 09-02-2009 12:09 AM

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 11:46 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.