Solved

ASP.NET change font size of a dropdownlist programatically

Posted on 2009-04-02
6
1,078 Views
Last Modified: 2012-05-06
Seems like the only way to get the text size of a dropdownlist to change is by using the Font-Size="X-Small" attribute in the aspx file.  Well, I'm building some dropdownlists in my code behind file (VB) and I can't seem to find that property or any other way to alter the font size of a dropdownlist when creating one dynamically.
Dim ddl As DropDownList = New DropDownList

        ddl.ID = "RestaurantFilter"
 

        Dim li As ListItem = New ListItem

        li.Text = "View All Restaurants"

        li.Value = "all"

        li.Selected = True

        ddl.Items.Add(li)
 

        li = New ListItem

        li.Text = "View Open Restaurants Only"

        li.Value = "open"

        ddl.Items.Add(li)

Open in new window

0
Comment
Question by:josephdaviskcrm
6 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 500 total points
Comment Utility
You can write some CSS to put in the page and set the .CssClass attribute of the dropdown box programatically
 

<style>

.ddSmall

{

   font-size:8pt;

}

</style>

...

ddl.Cssclass = "ddSmall";

Open in new window

0
 
LVL 3

Expert Comment

by:dipakdave1983
Comment Utility
all u can do is set class of dropdown.

so it will be like this

if(condtion true)
dropdown.attributes.add('class","smooth_css"); //smooth_css is css class
else
dropdown.attributes.add('class","hard_css"); //hard_css is css class
0
 

Author Closing Comment

by:josephdaviskcrm
Comment Utility
I of course had already tried it, but when I tried it before I used font-size:8px; instead of font-size:8pt; So it didn't work.  Using 'pt' works.  Thanks.

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 23

Expert Comment

by:apresto
Comment Utility
No problem, happy to help
Apresto
0
 
LVL 2

Expert Comment

by:jjamstrong
Comment Utility
try this
Dim ddl As DropDownList = New DropDownList
ddl.Font.Size = "X-Large"
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
You could use that, but what defines C-Large, you have alot more flexibility using CSS, stick with that :)
Apresto
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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 …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

16 Experts available now in Live!

Get 1:1 Help Now