Solved

ASP.NET change font size of a dropdownlist programatically

Posted on 2009-04-02
6
1,089 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
ID: 24051414
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
ID: 24051513
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
ID: 31565856
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 23

Expert Comment

by:apresto
ID: 24051579
No problem, happy to help
Apresto
0
 
LVL 2

Expert Comment

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

Expert Comment

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

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

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…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

803 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