Friday 6 January 2012

Binding Installed fonts in dropdownlist using LINQ

Namespace


using System.Drawing.Text;


Here is markup:

<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true">

    <asp:ListItem>--- Please select font ---</asp:ListItem>
</asp:DropDownList>

Paste code bellow and put on your page load event.
C#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InstalledFontCollection instedFontColl = new InstalledFontCollection();
            DropDownList1.DataSource = from font in instedFontColl.Families
                                       select font.Name;
            DropDownList1.DataBind();
        }
    }

No comments:

Post a Comment