Quantcast Binding Installed fonts in dropdownlist using LINQ

Binding Installed fonts in dropdownlist using LINQ

by Neon Quach 18. November 2009 04:20
In this blog I will give you snippet code which fetches installed font in dropdownlist in .NET using both C# and VB.NET.

Start with creating a new website using asp.net C# and VB.NET.
Drag a dropdownlist from toolbox into web page.

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();

        }

    }

VB.NET
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not Page.IsPostBack Then

            Dim fonts As New InstalledFontCollection()

 

            DropDownList1.DataSource = From font In fonts.Families _

                                       Select font.Name

            DropDownList1.DataBind()

        End If

    End Sub

Press F5 or Ctrl + F5 you will see the result like screenshot bellow.



Happy programming

 

Binding-Installed-fonts-in-dropdownlist-using-LINQ.rar (8.77 kb)

Tags: , , ,


Categories: asp.net | visual studio tips | c# | vb.net

blog comments powered by Disqus

About me

I'm  currently employed as Software developer at devinition.com and also a Microsoft Certified Technology Specialist (MCTS), Microsoft Certified Professional Developer (MCPD) in Net Framework 2.0 and 3.5: Web Applications and MCTS .NET Framework 3.5, ADO.NET Applications

Powered by BlogEngine.NET 2.5.0.5 - Eco Theme by n3o Web Designers