'Anil' Radhakrishna's Code Gallery

Home | Blog
Web Development Tips, Tricks & Trivia

Urdu to English Mini Dictionary

The source code here demonstrates a minimalistic web based interface (that utilizes the ASP.NET AJAX AutoComplete Extender) to a Urdu to English mini Dictionary database. This Dictionary table in SQL Server contains 3 columns WordId, Word & Meaning & it was extracted using DTS from a ascii text based dictionary compiled by a Urdu enthusiast in NASA, Dinesh Prabhu.
<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    [System.Web.Services.WebMethod]
    public static string[] GetCompletionList(string prefixText, int count)
    {
        string sql;
        sql = "select top " + count + " word + ' - ' + meaning from dictionary where word like @input + '%'";

        List<string> wordList = new List<string>();

        using (SqlConnection connection = new SqlConnection(@"Integrated Security=SSPI;Initial 
            Catalog=Pubs;Data Source=."))
        using (SqlCommand command = new SqlCommand(sql, connection))
        {
            connection.Open();
            command.Parameters.AddWithValue("@input", prefixText);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {
                    wordList.Add(reader.GetString(0));
                }
            }
        }

        return wordList.ToArray();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>Urdu to English Mini Dictionary</title>
</head>
<body>
    <form id="form1" runat="server">

        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <div>
            <asp:TextBox ID="myTextBox" runat="server" autocomplete="off" BackColor="Yellow"

                Width="500px"></asp:TextBox>
            <ajaxToolkit:AutoCompleteExtender   runat="server" 
                        ID="autoComplete1" 
                        TargetControlID="myTextBox"

                        ServiceMethod="GetCompletionList" 
                        MinimumPrefixLength="1" 
                        CompletionInterval="1000"
                        EnableCaching="true" 
                        CompletionSetCount="18" />

        </div>
    </form>
</body>
</html>

Read related blog posting
Code formatted with ASP.NET Resources code formatter.