Solved

ASP.NET change font size of a dropdownlist programatically

Posted on 2009-04-02
6
1,098 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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