Solved

Chnage the font on a checkbox list

Posted on 2013-05-13
3
299 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
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…

789 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