Solved

Chnage the font on a checkbox list

Posted on 2013-05-13
3
317 Views
Last Modified: 2013-05-19
Hello,

I have a checkboxlist where all labels are bold for each checkbox.  I want to be able to make every other checkbox label bold.  I believe I have to do it on the data bind on the page load property.  Can someone please help?  This is the code I have...it is not working so far.  I use Microsoft Visual Studio 2005, C#, and ASP.NET.  Here is the code behind.

        protected void Page_Load(object sender, EventArgs e)
        {
           
            ((MasterPage)this.Master).SelectedMenu = "Tables";
            if (!IsPostBack)
            {
                DataTable categories = GetCategories();
                CategoryList.DataSource = categories;
                CategoryList.DataTextField = "VehicleCategoryName";
                CategoryList.DataValueField = "VehicleCategoryID";
                CategoryList.DataBind();
            }
            SelectedCategories.Text = "";
         }

        public override void DataBind()
        {
            base.DataBind();

            for (int a = 0; a < CategoryList.Items.Count; a++)
            {
                if (a % 2 != 0)
                {
                    CategoryList.Font.Bold = true;
                }
            }

           
        }
0
Comment
Question by:valley025
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Expert Comment

by:muh_abbas
ID: 39163790
Hello valley025,

Add this function to your code behind and pass your checkboxlist in parameters, the bold style will be applied to all items.

Moreover, now you can add any style by the help of this function.


 
private void ChangeCheckBoxListStyle(CheckBoxList cbl)
        {
            for (int i = 0; i < cbl.Items.Count; i++)
            {

                cbl.Items[i].Attributes.Add("style", "font-weight: bold");
            }
        
        }

Open in new window



Regards,
Abbas
0
 

Accepted Solution

by:
valley025 earned 0 total points
ID: 39164721
protected void Page_Load(object sender, EventArgs e)
        {
           
            ((MasterPage)this.Master).SelectedMenu = "Tables";
            if (!IsPostBack)
            {
                DataTable categories = GetCategories();
                CategoryList.DataSource = categories;
                CategoryList.DataTextField = "VehicleCategoryName";
                CategoryList.DataValueField = "VehicleCategoryID";
                CategoryList.DataBind();
            }
            SelectedCategories.Text = "";
         }

        public void DataBind(object sender, EventArgs args)
        {
            for (int a = 0; a < CategoryList.Items.Count; a++)
            {
               
                if (a % 2 == 1)
                {
                    CategoryList.Items[a].Attributes.CssStyle["font-weight"] = "bold";
                }
            }
        }
0
 

Author Closing Comment

by:valley025
ID: 39178259
It works
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Testing of the web services 1 80
how to pass the "this" object from C# to a Java Script function. 2 40
c#, datatable, aspx 4 52
Ajax calendar distorted 4 21
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question