Friday 24 August 2012

How to add all System Fonts in DropdownList in .Net

How to add all System Font in DropdownList




using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

First add this name space ……..
using System.Drawing;

public partial class howtoaddallsystemfontindropdownlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ArrayList li;
            li = new ArrayList();



            FontFamily[] FontnameList = FontFamily.Families;
            foreach (FontFamily ff in FontFamily.Families)
            {
                string fnt;
                int ind = ff.ToString().IndexOf('=') + 1;
                int rndind = ff.ToString().Length - ind;
                fnt = ff.ToString().Substring(ind, rndind - 1);
                li.Add(fnt);
            }
            DropDownList1.DataSource = li ;
            DropDownList1.DataBind();

        }
    }
}

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="howtoaddallsystemfontindropdownlist.aspx.cs" Inherits="howtoaddallsystemfontindropdownlist" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            width: 100%;
            table-layout:fixed ;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
    </div>
    <table class="style1">
        <tr>
            <td>
                &nbsp;</td>
            <td>
                <asp:DropDownList ID="DropDownList1" runat="server" >
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>
</body>
</html>

0 comments: