473,396 Members | 1,997 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,396 software developers and data experts.

How to format "Drop Down List" TextFields C#

missshaikh
Hi All Friends.

I need your help..

I want to format Bold Italic in Drop Down List Control in C#.i retrieve my data from db.

like this .

________________
CD ROOM
CD-R Sony
CD-R HP
DVD- Room
Motherboard
Intell PIII
Intell PII
IBM PII
DEL PIII
KeyBoard-Mouse
Dell Keybord
SP Keybord
HDD Disk
Segat HDD Disk
40GB HDD
180GB HDD


i want to show like this in my ddl C# from DB. I need to know how to formate ddl????

:( plzzzzzz Answare me
Jul 2 '07 #1
1 8447
nateraaaa
663 Expert 512MB
Hi All Friends.

I need your help..

I want to format Bold Italic in Drop Down List Control in C#.i retrieve my data from db.

like this .

________________
CD ROOM
CD-R Sony
CD-R HP
DVD- Room
Motherboard
Intell PIII
Intell PII
IBM PII
DEL PIII
KeyBoard-Mouse
Dell Keybord
SP Keybord
HDD Disk
Segat HDD Disk
40GB HDD
180GB HDD


i want to show like this in my ddl C# from DB. I need to know how to formate ddl????

:( plzzzzzz Answare me
I have researched many sites trying to find the answer to this question. This is what I found that seemed to be the most helpful.

Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, System.EventArgs e) {
  2.         SqlDataReader dr;
  3.         string CONNECTION_STRING = "Data Source=MCN004;Initial Catalog=student;Integrated Security=True";
  4.         string sQuery = "select Rollno, Name, Course from student";
  5.         SqlConnection cn = new SqlConnection(CONNECTION_STRING);
  6.         SqlCommand cmd = new SqlCommand(sQuery, cn);
  7.         cn.Open();
  8.         dr = cmd.ExecuteReader;
  9.         while (dr.Read) {
  10.             ListItem li = new ListItem(dr["Name"], dr["Course"]);
  11.             switch (dr["Rollno"]) {
  12.                 case 1:
  13.                     li.Attributes.Add("style", "color:red");
  14.                     break;
  15.                 case 2:
  16.                     li.Attributes.Add("style", "color:Green");
  17.                     break;
  18.                 case 3:
  19.                     li.Attributes.Add("style", "color:voilet");
  20.                     break;
  21.                 case 4:
  22.                     li.Attributes.Add("style", "color:darkolivegreen");
  23.                     break;
  24.                 default:
  25.                     li.Attributes.Add("style", "color:fuchsia");
  26.                     break;
  27.             }
  28.             ddlStudent.Items.Add(li);
  29.         }
  30.         cn.Close();
  31.     }
To change this and make the text bold replace color:whatever with font-weight:bold and to make it italic you will need to use font-style:italic.
I would prefer using something other than a switch statement here but give this a try and let us know if this will work for you.

Nathan
Jul 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Larry R Harrison Jr | last post by:
I am looking for javascript and a basic tutorial on how to make mouse-over drop-down menus--the type that when you "hover" over a subject links relevant to that subject "emerge" which you can then...
4
by: Larry R Harrison Jr | last post by:
I have them working now, courtesy of the link given in the prior thread--the HVMenu over at Dynamic Drive myself. http://www.dynamicdrive.com I have them working as side-bar menus, not...
1
by: John | last post by:
Hi everyone. I'm having a real problem with a drop-down menu that I'm using. Simply, as I scroll down the page, it follows me. I don't want this!! I guess it's all my fault for using...
2
by: Kyle Blaney | last post by:
I am using a Listbox and can not get the "drop down" effect. My listbox is populated with 20 items and a vertical scrollbar is automatically added. One item is visible. When I click on the...
0
by: Alan | last post by:
I 'm new for .NET, and actually on my own to develop my employer's web application. I can't bind my dropDownList control to entries in the database. Here is a code:...
4
by: charliewest | last post by:
I need to set the selected drop down list value at run time. I am aware of the method "SelectIndex" however this works only if you know the precise location of the value within the ListItem...
4
by: charliewest | last post by:
Hello - I've binded a dataset to a Drop Down List control on my web form, using C#, however, the DateTime value is printed in long format. For example: 04/07/2006 12:00 AM. My code is: ...
2
by: Doogly | last post by:
Hello everyone, I'm really new to Javascript and was wondering if anyone could give me code for a nice looking drop down menu. Ideally it would do that little scrolly animation thingy when it...
2
by: Doug | last post by:
Hi, I can't figure out how to create a drop-down list box. The help file says it exists. The icon in the help file matches the combobox in the toolbox. I tried using a combox box, both with and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.