473,385 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Style DropDownList's ListItems Individually

I want to display a drop-down list (System.Web.UI.WebControls.DropDownList)
loaded with font names the user can select (Verdana, Garamond, etc)... got
this far no problem.

Now I'd like to have the list show ListItem styled with the font being
listed (ie., the "Verdana" ListItem is styled as Verdana).

Here's my code that doesn't work. Note fontFaces is a string array that
lists the fonts being loaded into the DDL).

for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
DDL_Fonts.Items.Add(nextItem);
}

What would it take to accomplish the effect I'm after?

Thanks!
Nov 18 '05 #1
7 8548
nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
fontFaces[i]);

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl...
I want to display a drop-down list (System.Web.UI.WebControls.DropDownList) loaded with font names the user can select (Verdana, Garamond, etc)... got
this far no problem.

Now I'd like to have the list show ListItem styled with the font being
listed (ie., the "Verdana" ListItem is styled as Verdana).

Here's my code that doesn't work. Note fontFaces is a string array that
lists the fonts being loaded into the DDL).

for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
DDL_Fonts.Items.Add(nextItem);
}

What would it take to accomplish the effect I'm after?

Thanks!

Nov 18 '05 #2
....didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
fontFaces[i]);

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl...
I want to display a drop-down list

(System.Web.UI.WebControls.DropDownList)
loaded with font names the user can select (Verdana, Garamond, etc)... got this far no problem.

Now I'd like to have the list show ListItem styled with the font being
listed (ie., the "Verdana" ListItem is styled as Verdana).

Here's my code that doesn't work. Note fontFaces is a string array that
lists the fonts being loaded into the DDL).

for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]); nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
DDL_Fonts.Items.Add(nextItem);
}

What would it take to accomplish the effect I'm after?

Thanks!


Nov 18 '05 #3
try with no strokes:

nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);

should work.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
...didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
fontFaces[i]);

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl...
I want to display a drop-down list

(System.Web.UI.WebControls.DropDownList)
loaded with font names the user can select (Verdana, Garamond, etc)... got this far no problem.

Now I'd like to have the list show ListItem styled with the font being
listed (ie., the "Verdana" ListItem is styled as Verdana).

Here's my code that doesn't work. Note fontFaces is a string array that lists the fonts being loaded into the DDL).

for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]); nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
DDL_Fonts.Items.Add(nextItem);
}

What would it take to accomplish the effect I'm after?

Thanks!



Nov 18 '05 #4
still no dice... The DDL gets populated with the list of fonts as expected -
just not styled.

Here is all my code - exactly as I have it - including your most recent
suggestion.

IN CODE-BEHIND (executes in Page_Load if not PostBack):

string[] fontFaces = dataClass.GetFontsList();
for (int i=0; i < (fontFaces.GetUpperBound(0) + 1); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);
DDL_txtFont.Items.Add(nextItem);
}
IN HTML:
<asp:DropDownList CssClass="ddlText1" id="DDL_txtFont" AutoPostBack="false"
EnableViewState="true" Width="150px" runat="server"></asp:DropDownList>


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
try with no strokes:

nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);

should work.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
...didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
fontFaces[i]);

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OK*************@TK2MSFTNGP10.phx.gbl...
> I want to display a drop-down list
(System.Web.UI.WebControls.DropDownList)
> loaded with font names the user can select (Verdana, Garamond, etc)...
got
> this far no problem.
>
> Now I'd like to have the list show ListItem styled with the font
being > listed (ie., the "Verdana" ListItem is styled as Verdana).
>
> Here's my code that doesn't work. Note fontFaces is a string array

that > lists the fonts being loaded into the DDL).
>
> for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
> System.Web.UI.WebControls.ListItem nextItem = new

ListItem(fontFaces[i]);
> nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
> DDL_Fonts.Items.Add(nextItem);
> }
>
> What would it take to accomplish the effect I'm after?
>
> Thanks!
>
>



Nov 18 '05 #5
Bad news. DDL emits html <select> with an <option> for every ListItem. And
<option> doesn't support font settings in style.

You can tricking it by using stylesheets with class= unstead of style=. I
doubt it will help though.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:ur*************@TK2MSFTNGP11.phx.gbl...
still no dice... The DDL gets populated with the list of fonts as expected - just not styled.

Here is all my code - exactly as I have it - including your most recent
suggestion.

IN CODE-BEHIND (executes in Page_Load if not PostBack):

string[] fontFaces = dataClass.GetFontsList();
for (int i=0; i < (fontFaces.GetUpperBound(0) + 1); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);
DDL_txtFont.Items.Add(nextItem);
}
IN HTML:
<asp:DropDownList CssClass="ddlText1" id="DDL_txtFont" AutoPostBack="false" EnableViewState="true" Width="150px" runat="server"></asp:DropDownList>


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
try with no strokes:

nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);

should work.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
...didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
> nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
> fontFaces[i]);
>
> Eliyahu
>
> "Doug" <Cl******@Livermore.com> wrote in message
> news:OK*************@TK2MSFTNGP10.phx.gbl...
> > I want to display a drop-down list
> (System.Web.UI.WebControls.DropDownList)
> > loaded with font names the user can select (Verdana, Garamond, etc)... got
> > this far no problem.
> >
> > Now I'd like to have the list show ListItem styled with the font being > > listed (ie., the "Verdana" ListItem is styled as Verdana).
> >
> > Here's my code that doesn't work. Note fontFaces is a string array

that
> > lists the fonts being loaded into the DDL).
> >
> > for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
> > System.Web.UI.WebControls.ListItem nextItem = new
ListItem(fontFaces[i]);
> > nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
> > DDL_Fonts.Items.Add(nextItem);
> > }
> >
> > What would it take to accomplish the effect I'm after?
> >
> > Thanks!
> >
> >
>
>



Nov 18 '05 #6
Please note that in the HTML in my last post the following attribute was
included in the DDL declaration: CssClass="ddlText1"
I removed that - and the problem still persists (i.e., no styling as
expected from the code-behind).

"Doug" <Cl******@Livermore.com> wrote in message
news:ur*************@TK2MSFTNGP11.phx.gbl...
still no dice... The DDL gets populated with the list of fonts as expected - just not styled.

Here is all my code - exactly as I have it - including your most recent
suggestion.

IN CODE-BEHIND (executes in Page_Load if not PostBack):

string[] fontFaces = dataClass.GetFontsList();
for (int i=0; i < (fontFaces.GetUpperBound(0) + 1); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);
DDL_txtFont.Items.Add(nextItem);
}
IN HTML:
<asp:DropDownList CssClass="ddlText1" id="DDL_txtFont" AutoPostBack="false" EnableViewState="true" Width="150px" runat="server"></asp:DropDownList>


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
try with no strokes:

nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);

should work.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
...didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
> nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
> fontFaces[i]);
>
> Eliyahu
>
> "Doug" <Cl******@Livermore.com> wrote in message
> news:OK*************@TK2MSFTNGP10.phx.gbl...
> > I want to display a drop-down list
> (System.Web.UI.WebControls.DropDownList)
> > loaded with font names the user can select (Verdana, Garamond, etc)... got
> > this far no problem.
> >
> > Now I'd like to have the list show ListItem styled with the font being > > listed (ie., the "Verdana" ListItem is styled as Verdana).
> >
> > Here's my code that doesn't work. Note fontFaces is a string array

that
> > lists the fonts being loaded into the DDL).
> >
> > for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
> > System.Web.UI.WebControls.ListItem nextItem = new
ListItem(fontFaces[i]);
> > nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
> > DDL_Fonts.Items.Add(nextItem);
> > }
> >
> > What would it take to accomplish the effect I'm after?
> >
> > Thanks!
> >
> >
>
>



Nov 18 '05 #7
You can do this kind of thing using Javascript; check out http://webfx.eae.net/dhtml/select/jsGenerated.html (for IE)

If you are using a gecko browser you can probably get the font-size directly using CSS.

Scott
"Doug" <Cl******@Livermore.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
Please note that in the HTML in my last post the following attribute was
included in the DDL declaration: CssClass="ddlText1"
I removed that - and the problem still persists (i.e., no styling as
expected from the code-behind).

"Doug" <Cl******@Livermore.com> wrote in message
news:ur*************@TK2MSFTNGP11.phx.gbl...
still no dice... The DDL gets populated with the list of fonts as expected - just not styled.

Here is all my code - exactly as I have it - including your most recent
suggestion.

IN CODE-BEHIND (executes in Page_Load if not PostBack):

string[] fontFaces = dataClass.GetFontsList();
for (int i=0; i < (fontFaces.GetUpperBound(0) + 1); i++) {
System.Web.UI.WebControls.ListItem nextItem = new ListItem(fontFaces[i]);
nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);
DDL_txtFont.Items.Add(nextItem);
}
IN HTML:
<asp:DropDownList CssClass="ddlText1" id="DDL_txtFont" AutoPostBack="false" EnableViewState="true" Width="150px" runat="server"></asp:DropDownList>


"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eE**************@tk2msftngp13.phx.gbl...
try with no strokes:

nextItem.Attributes["style"]=String.Format ("font-family:{0}",
fontFaces[i]);

should work.

Eliyahu

"Doug" <Cl******@Livermore.com> wrote in message
news:OQ**************@tk2msftngp13.phx.gbl...
...didn't work... any other ideas?

"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:OJ**************@TK2MSFTNGP11.phx.gbl...
> nextItem.Attributes["style"]=String.Format ("font-family:'{0}'",
> fontFaces[i]);
>
> Eliyahu
>
> "Doug" <Cl******@Livermore.com> wrote in message
> news:OK*************@TK2MSFTNGP10.phx.gbl...
> > I want to display a drop-down list
> (System.Web.UI.WebControls.DropDownList)
> > loaded with font names the user can select (Verdana, Garamond, etc)... got
> > this far no problem.
> >
> > Now I'd like to have the list show ListItem styled with the font being > > listed (ie., the "Verdana" ListItem is styled as Verdana).
> >
> > Here's my code that doesn't work. Note fontFaces is a string array

that
> > lists the fonts being loaded into the DDL).
> >
> > for (int i=0; i < (fontFaces.GetUpperBound(0)); i++) {
> > System.Web.UI.WebControls.ListItem nextItem = new
ListItem(fontFaces[i]);
> > nextItem.Attributes.CssStyle.Add("font-family", fontFaces[i]);
> > DDL_Fonts.Items.Add(nextItem);
> > }
> >
> > What would it take to accomplish the effect I'm after?
> >
> > Thanks!
> >
> >
>
>



Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DesignerX | last post by:
I am being sent an ArrayList of ListItems. I can bind to a dropdownlist control using: oDropDownList.DataSource = oArrayList This works but when the dropdownlist is rendered both the select...
4
by: Luis Esteban Valencia | last post by:
Hi Everyone, How do you get two or more listitems to have the same value? I am trying to do this: <asp:dropdownlist id="one" runat="server"> <asp:listitem text="hello" value="hi" />
1
by: Jeff | last post by:
Hi - I'm creating a web control library (using VB.NET), and I'm trying to add a modified asp:dropdownlist control to it. How do I add asp:ListItems to the dropdownlist (within the web control...
1
by: HoustonFreeways | last post by:
I am populating a dropdownlist via a databind to a database. However, the text to be displayed can be very long, making the dropdownlist very wide. I need some way to reduce the width of the...
1
by: Geoffrey van den Ouden | last post by:
I'm converting this project from ASP.NET 1.1 to 2.0, and the thing I came across is that my dropdownlist no returns the content of the Value property in a correct way. I'm not using a direct...
0
by: Jose Fernandez | last post by:
Hello First of all, excuse my english We all know that in a normal page with codebehind we add a dropdownlist control and we bind() it in the (!ISPOSTBACK), so, we don't need to go to database...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
5
by: Mark Rae | last post by:
Hi, Here's one just for my own interest - I know how to add ListItems programatically, and how to concatenate fields in SQL queries... But, is there any way to specify anything other than a...
1
by: Nathan Sokalski | last post by:
I am creating a control in which I inherit from the DropDownList. The only method that I override is RenderContents. Here is my basic code: Public Class StatesDropDownList : Inherits DropDownList...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.