473,503 Members | 9,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckBoxList with style color

4 New Member
Hi,

I am populating the checkboxlist in (!IsPostBack) block of page load event
with some checked items.

After populating with checked items I am iterating through the items collection and applying color style for checked items.

The below method is called from !IsPostBack()
Expand|Select|Wrap|Line Numbers
  1.  public static void PopulateCheckBoxList(CheckBoxList checkBoxList, ArrayList nameValueList, ArrayList selectedItemsList)
  2.         {
  3.             checkBoxList.Items.Clear();
  4.             foreach (NameValueItem item in nameValueList)
  5.             {
  6.                 ListItem li = new ListItem(item.ItemName, item.ItemValue.ToLower());
  7.                 checkBoxList.Items.Add(li);
  8.             }
  9.  
  10.             foreach (NameValueItem item in selectedItemsList)
  11.             {
  12.                 checkBoxList.Items.FindByValue(item.ItemValue.ToLower()).Selected = true;
  13.                 checkBoxList.Items.FindByValue(item.ItemValue.ToLower()).Attributes.Add("class", "selectedCheckBoxListItem");
  14.             }
  15.         }
The Issue:

when the page is postedback, checkboxlist retaining its selections but losing its color style for selected items.

Please let me know why , the applied style attribute is not loaded in to viewstate.

Thanx & Regards,
only
Nov 24 '09 #1
3 5853
Frinavale
9,735 Recognized Expert Moderator Expert
Are you using Ajax?
Sometimes the styles aren't properly loaded after an asynchronous postback.

I'm not sure why the class wouldn't be loaded into ViewState....

-Frinny
Nov 25 '09 #2
onlyprad
4 New Member
Thanx Frinny.

I am not using AJAX.

Its fixed now.

I changed the code from:

checkBoxList.Items.FindByValue(item.ItemValue.ToLo wer()).Attributes.Add("class", "selectedCheckBoxListItem");

to:

checkBoxList.Items.FindByValue(item.ItemValue.ToLo wer()).Text = "<span class=\"selectedCheckBoxListItem\">" + checkBoxList.Items.FindByValue(item.ItemValue.ToLo wer()).Text + "</span>";



The difference in rendered HTML in the baove two is,

in the first case, <span class="selectedCheckBoxListItem"> is added outside the label containing the listitem text. And this span is not postedback.

in the second case, <span class="selectedCheckBoxListItem"> is added insode the listitem label, but around the label text value. This span is postedback and there is no style loss.

Regards,
only
Nov 25 '09 #3
Aikanaro
1 New Member
@onlyprad


Thank you very much for solution.
Jan 21 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
7931
by: Bryce Budd | last post by:
Hello All, I've been a taker of information from newsgroups for a long time and thought I'd finally make a contribution back to the community whose supported me when I've needed it. After all...
3
5441
by: Robin Day | last post by:
I run some code on the changed event of checkbox lists. Its quite simple, nothing more than showing / hiding some other parts of the page. Using Autopostback and Server side code works fine, but is...
4
6503
by: Shaul Feldman | last post by:
Hello, I have something really awkward at work - fighting with CheckBoxList... How can I define CSS for ListItem in CheckBoxList programmatically. I add CheckBoxList's Items on the fly, something...
3
5713
by: Jack Black | last post by:
Using VS.Net 2k3 to build ASP.Net app with VB code-behind pages... Hi, all! I've been struggling with getting a dynamically-generated CheckBoxList generated. I've finally been able to get the...
7
15623
by: bienwell | last post by:
Hi, I'm using the CheckBoxList control in ASP.NET for Web development. This checkboxlist is bound by the database. If we have more items for this checkbox list, it takes space on the page. I...
7
2219
by: ThunderMusic | last post by:
Hi, I have a CheckBoxList and I want to add some javascript code to each CheckBox created by this CheckBoxList. I tried iterating through all items of the list, all the controls, do a FindControl,...
3
3765
by: Sully | last post by:
Hi, I am having a small problem generating an e-mail via an online form. I am creating an e-mail using the MailMessage command and I know that you have to do something special to render the values...
0
2152
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
2400
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7095
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7361
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7015
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5602
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.