How to create dynamic Hindi website using ASP.Net

 

Introduction

In this article i will teach you how to create dynamic database driven Hindi website using Asp.Net with C#.net.

History

In the Previous articles i explained how to retrieve year from date in c#.nethow to retrieve day from date in sqlhow to retrieve month from date in sqlhow to retrieve year from date in sql, how to change my computer language to hindi.

Step 1.

Instead of using any specific Hindi font, you can use global font which supports UTF-8.
Its helpful when your site visitors don't have particular hindi font on their computer. It also able visitors to see your site without downloading any font or without setting into their computer.

For that if you are using windows, then you have to set up your computer language to Hindi.(with doing this you can see Hindi font into your editor or textBox insted of square boxes.)

See my previous article How to change my computer's keyboard typing language.

Step 2.

Now, by going through above article i can assume that you configured your PC to type in Hindi Language. Now, we can go to next step.

We will create two pages one for inserting data into database and one for displaying inserted data in Hindi. i.e "insert-data.aspx" and "display-data.asox".

Step 3.

Create database table having a "content_data" column with "ntext" Data Type for inserting Hindi content.

Step 4.

Drag and Drop one TextBox, Label and  a Button control from toolbox into "insert-data.aspx" page.

Set TextBox "TextMode" property to MultiLine and a button text property to "Submit".

Step 5.

Write below code on "Click" event of the button.

    string dbstring = ConfigurationManager.ConnectionStrings["database_con"].ConnectionString;
        SqlConnection con = new SqlConnection(dbstring);
        con.Open();
        string query = "Insert into table1(id,content_data)values('1',N'" + textBox1.Text + "');";
        SqlCommand cmd = new SqlCommand(query, con);
        cmd.ExecuteNonQuery();
        Label1.Text = "Data Submitted Successfully.";
        con.Close();

Note* : Make sure to put "N" before textbox value in sql query. This denotes that the subsequent string is in Unicode (the N actually stands for National language character set). Which means that you are passing an NCHAR, NVARCHAR or NTEXT value, as opposed to CHAR, VARCHAR or TEXT. 

Step 6.

Drag and drop a "Label" control on "display-data.aspx" page. and give id as lbl_hindi.

Step 7.

Write the below code on load event of the "display-data.aspx" page.

    string dbstring = ConfigurationManager.ConnectionStrings["database_con"].ConnectionString;
        SqlConnection connection = new SqlConnection(dbstring);
        connection.Open();
        SqlCommand ad = new SqlCommand("select content_data from table1 where id='1'", connection);
        SqlDataReader dr = ad.ExecuteReader();

        if (dr.Read())
        {
            lbl_hindi.Text = dr.GetString(0);
        }

        connection.Close();

That's It. Now test your application.

Step 8.

Run "insert-data.aspx" page. Type something in a textBox in Hindi and click on Submit button.

Step 9.

Now as the data is inserted in database using the above step. Now run "display-data.aspx" page.

You can see the Hindi data on your webpage without any font embedding.

Screenshot. 

Now you have the idea of how to create a website in Hindi. Now you can go with full-furnished website in Hindi.

Enjoy!

 

Give your Valuable Comments.
comments powered by Disqus
 
Follow me on twitter
About Me
Harpreet Singh
I began programming with C++ when i was 17. Then at the middle of my study .NET came. Then I began to read C# and VB.NET. By the time i learnt SQL and ASP.NET, and developed some websites such as news portals that are active now. Currently i am running my own Software company.
More Articles