Solved

ASP.NET change font size of a dropdownlist programatically

Posted on 2009-04-02
6
1,084 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET website keeps me current? 9 56
Run time Error 4 34
ASP.net Javascript use multiple sliders 2 17
Entity Framework 7 31
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

21 Experts available now in Live!

Get 1:1 Help Now