0

I have a DropDownlist(DDL) which is populated by Database from Client Side.

I want to change font-family or Change CSS Class of particular items in DDL depending on some conditions (on DataValue Field basis of DDL).

I have tried following code:

protected void ddlAuthor1_OnDataBinding(object sender, EventArgs e)
{
    foreach (ListItem item in ddlAuthor1.Items)
    {
        if (int.Parse(item.Value) == 1)
        {
            item.Attributes.Add("style", "font-family:AmrLipi;");
        }
    }
    upBookEntryForm.Update();

}

But it didnot work for me. I tried this code in OnDataBound event also but no success.

Please Help me on this issue

  • try this > item.Attributes.Add("style", "font-family:'AmrLipi',Arial;"); – Amit Jul 14 '14 at 10:47
  • Hi Amit, whats the difference in my code and your code?? – Chandan Garg Jul 14 '14 at 10:56
  • Note, that adding font styling to individual – ben Jul 14 '14 at 10:56
  • wrapping 'AmrLipi' with single quote + adding Arial for backup font – Amit Jul 14 '14 at 10:58
  • [This could also help](http://stackoverflow.com/questions/1895476/how-to-style-a-select-dropdown-with-css-only-without-javascript) – Pete Jul 14 '14 at 11:31

0 Answers0