Solved

Chnage the font on a checkbox list

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

615 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