Solved

Chnage the font on a checkbox list

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now