Formatting dropdown list

Posted by Vijayar under C# on 5/5/2011 | Points: 10 | Views : 8792 | Status : [Member] | Replies : 9
Hi
I have one dropdown list box,i am binding values from the database,is it possible to show some values in bold and other values normally,help me on this issue

vijaya


Responses

Posted by: Prabhakar on: 5/5/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Vijay. .


I think you write code when you Fill Ur DropDownList with ur Condition . . some thing Like this Try it . .

if (ddlcountry.Items[0].Text == "India")

{
ddlCountry.BackColor = System.Drawing.Color.Blue;
}




Best Regard's
Prabhakar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/5/2011 [Member] Starter | Points: 25

Up
0
Down
i am getting values from database and binding them to dropdown

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 5/5/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
HI Vijayar


Show ur Code . . Which way u exactly Fetch Data

Best Regard's
Prabhakar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vijayar on: 5/5/2011 [Member] Starter | Points: 25

Up
0
Down
Ex: query Select cityname,city id from city
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind(); i want all city names in bold

vijaya

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 5/5/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Vijay

set with DropdownList property to All Cities

style=" font-weight:bold;"

It's help u . .



Best Regard's
Prabhakar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 5/5/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Vijay . . .


And also if u want to do with code to do this . .


DropDownList1.Attributes.Add("style", "font-weight:bold");


Best Regard's
Prabhakar

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 5/5/2011 [Member] Bronze | Points: 25

Up
0
Down
Can you check whether this post is helpful.

http://www.velocityreviews.com/forums/t360823-format-text-in-dropdownlist.html

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bhaarat287 on: 5/5/2011 [Member] Starter | Points: 25

Up
0
Down
hii
here i have done it to set color for each item in dropdownlist
In my Case the Color code comes from database.
and accordingly i m displaying the items in dropdown

Try it and let me know the status

private void UpdateDdlColor()
{
var count = (from objlst in ddlMediator.Items.Cast<ListItem>()
select Changecolor(objlst, UsersList)).Count();
}

private bool Changecolor(ListItem objlst, List<EntyInfo> UsersList)
{

string strcolorName = (from objUserlst in UsersList
where objUserlst.UserId == Convert.ToInt64(objlst.Value)
select objUserlst.ColorName).FirstOrDefault();

objlst.Attributes.Add("style", string.Format("color:{0}", strcolorName));
return true;
}



All the Best

Bhaarat

http://ransandeep.blogspot.com

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 5/9/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
You can loop through all the items.

foreach (ListItem item in DropDownList1.Items)
{
//if you want to apply for some selected items check the condition on item.Text or item.Value based on your requirement.
if (item.Text == "Some Value")
{
//Change font weight
item.Attributes.CssStyle.Add("font-weight", "bold");
//Change font color
item.Attributes.CssStyle.Add("color", "red");
}
}

* Please note that font-weight and font-size is not rendered properly in IE, you can see the difference in Firefox etc. So try to use the color property to distinguish.
Thanks,
Debata

Vijayar, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response