Solved

ASP.NET change font size of a dropdownlist programatically

Posted on 2009-04-02
6
1,092 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

790 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