Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Checkboxes in a ListView losing checked attribute on postback

Reply
Thread Tools

Checkboxes in a ListView losing checked attribute on postback

 
 
tom
Guest
Posts: n/a
 
      09-02-2009
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;cursorointer;");

}

else

{

checkBoxPolicy.Attributes.Add("style", "color:#07447B;cursor:default;");

}


Thanks in advance,

Tom

ASP.NET 3.5


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp.net ListView control - Configure ListView option missing? . ASP .Net 0 07-24-2010 12:20 AM
CheckBox Checked=false when checked in DataList yurps ASP .Net 1 02-29-2008 01:08 PM
CheckBoxes in DataGrids-- the "checked" attribute not correct after posting page? Jim Bancroft ASP .Net Datagrid Control 4 08-04-2005 04:19 PM
CheckBoxes in DataGrids-- the "checked" attribute not correct after posting page? Jim Bancroft ASP .Net 4 08-04-2005 04:19 PM
Checkboxes checked in runtime datagrid DJ Dev ASP .Net 7 02-10-2004 05:41 PM



Advertisments