Solved

Chnage the font on a checkbox list

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert html to string 6 34
Delete HTML table rows 12 28
i have to take the screenshot of command prompt? how to do this? 1 37
asp.net mvc5 6 16
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
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 …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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