August 29, 2012

Insert Multiples Row Into Single Table

Acheive target with minimal cost is hot topic now a days. SQL Server provides different approaches to acheive targets. Here I can show you these approaches.

USE DBTester

-- Create Table

TestId int not null,
TestValue nvarchar(100) not null

-- Beginner Approach I

INSERT INTO Test (TestId, TestValue)
VALUES 1, 'One'

INSERT INTO Test (TestId, TestValue)
VALUES 2, 'Two'

INSERT INTO Test (TestId, TestValue)
VALUES 3, 'Three'


-- Beginner Approach II

INSERT INTO Test (TestId, TestValue)
SELECT 1, 'One'

INSERT INTO Test (TestId, TestValue)
SELECT 2, 'Two'

INSERT INTO Test (TestId, TestValue)
SELECT 3, 'Three'


-- Intermediate Approach

INSERT INTO Test (TestId, TestValue)
SELECT 1, 'One'
SELECT 2, 'Two'
SELECT 3, 'Three'


-- Advance Approach (SQL 2008 Feature named as Row Construction)

INSERT INTO Test (TestId, TestValue)
VALUES (1, 'One'), (2, 'Two'), (3, 'Three');



August 28, 2012

Encrypt / Decrypt web.config ConnectionString

I am using RSA Protected Configuration Provider Model to encrypt and decrypt
<connectionstring> section
in web.config file.

Create a method in class library to encrypt decrypt on button click event.

protected void btnEncrypt_OnClick(object sender, EventArgs e)

protected void btnDecrypt_OnClick(object sender, EventArgs e)

protected void EncryptDecrypt(bool statusValue)
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var section = configuration.GetSection("connectionStrings");

if (statusValue == true)
if (!section.SectionInformation.IsProtected)
if (section.SectionInformation.IsProtected)


August 16, 2012

ASP.NET Web Parts

In ASP.NET terminology, Web parts are components that have some predefined functionality and they can be embedded in any web page. User can change the appearance and data related parameters of all web parts independently.

Advantages of Web Parts

  • Web Parts facilitate personalization of page content. They let the users to move or hide the Web Parts and add new Web Parts changing the page layout.
  • Web Parts let the user to export or import Web Parts settings for use in other pages.
  • Web Parts can work in unison with ASP.NET role-based web access model. Each Web Part can be configured to be visible or hidden for any role.
  • Web Parts can share data with each other.

Before starting the code, let us look at few of the controls and terminologies that are useful in implementing web parts.

  • WebPartsManager: This is a non visual control that has to be added on every page that needs to have web parts embedded in them. This control will facilitate the management of different web parts on a page.
  • CatalogPart: This control is for managing the UI elements of all the web part available on a page. This control manages the web parts for the whole website.
  • PageCatalogPart: This control provides the same functionality as the CatalogPart but it does it for an individual page rather than for the complete web site.
  • EditorPart: This control lets the user customize the properties of web parts.
  • WebPartZOne: This control is like a container for web parts. Any web part can be added to WebPartZone only.
  • EditorZone: This control is like a container for EditorParts. Any EditorPart can be added on EditorZone only.
  • CatalogZone: This control is like a container for CatalogParts. Any CatalogPart can be added on CatalogZone only.

Also let's take a quick look at the different modes the web parts can have before going in details.

Web Parts Modes

  • Normal mode: The user cannot edit or move sections of page.
  • Edit Mode: End user can edit Web Parts on the page including Web Parts title, color or even setting custom properties.
  • Design Mode: End user can rearrange the order of the pages Web Parts in a WebPartZone.
  • Catalog Mode: End user can add new Web Parts or add deleted Web Parts in any WebPartZone on the page.

The basic tutorial of web parts is as below:


<asp:WebPartManager ID="WebPartManager1" runat="server">
<asp:WebPartZone ID="WebPartZoneHeader" runat="server" Height="1px" Width="865px"
<asp:Label ID="welcomeWebPart" runat="server" Text="User" title="Welcome" Width="199px" />
<asp:WebPartZone ID="WebPartZoneContent" runat="server" Height="1px" Width="865px"
HeaderText="Pick a Day">
<asp:TextBox ID="TextBoxName" runat="server" Title="Enter your name">
<asp:DropDownList ID="DropDownList1" runat="server" Title="Change Display modes"
AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:Calendar ID="CalendarWebPArt" runat="server" title="Pick a day"></asp:Calendar>
<asp:CatalogZone ID="CatalogZone1" runat="server">
<asp:PageCatalogPart ID="PageCatalogPart1" runat="server" />
<asp:WebPartZone ID="WebPartZoneFooter" runat="server" Height="35px" Width="865px"
<asp:Label ID="footerWebPart" runat="server" Text="This is a test website." title="Copyright info"></asp:Label>


protected void Page_Load(object sender, EventArgs e)
welcomeWebPart.Text = TextBoxName.Text;
if (IsPostBack == false)
foreach (WebPartDisplayMode mode in WebPartManager1.SupportedDisplayModes)

DropDownList1.SelectedValue = WebPartManager1.DisplayMode.ToString();
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
if (WebPartManager1.SupportedDisplayModes[DropDownList1.SelectedValue] != null)
WebPartManager1.DisplayMode = WebPartManager1.SupportedDisplayModes

Space in Regular Expression

Best approach is to create a method in js file using jquery to create space in regular expression

function (value, element) {
var alphaRegExp = new RegExp("^[\\sa-zA-Z]*$");
if (alphaRegExp.test(element.value)) {
return true;
else return false;
"Please enter alphabet"

Json Format Getting Multiples ID

There is quite simple and easy way to get multiple ID's from json return string using javascript. If my desire output result will be as below


If i want to retrieve ChildLevelId as 5,13,14 then use below code. Modify it according to your need.


var myArr = [{ "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 5, "HierarchyLevel1": null, "HierarchyLevel2": null }, { "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 13, "HierarchyLevel1": null, "HierarchyLevel2": null }, { "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 14, "HierarchyLevel1": null, "HierarchyLevel2": null}];

var ChildArry = [];
for (var i = 0; i < myArr.length; i++) {
var Child = {};
Child.ChildLevelId = myArr[i].ChildLevelId;
ChildArry[i] = Child;

var finalOutput = JSON.stringify(ChildArry)


var data = [{ "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 5, "HierarchyLevel1": null, "HierarchyLevel2": null },
{ "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 13, "HierarchyLevel1": null, "HierarchyLevel2": null },
{ "RelationLevel1Id": 0, "ParentLevelId": 0, "ChildLevelId": 14, "HierarchyLevel1": null, "HierarchyLevel2": null}];
var childIDonly = $.map(data, function(a, i) {
return a.ChildLevelId;
var ids = JSON.stringify(childIDonly);

Accordion Control error in Wizard control

In Ajax Toolkit, Accordion control is very fancy and commonly use in different areas. Easy to implement control, sometimes generate error for some users.

Many users on different forums asked that they unable to view Accordion panel in design view of Visual Studio IDE and instead of panel they saw that below mention sentence.

Error Creating Control - Accordion1

Type "AjaxControlToolKit.Accodion" doesnot have a public property named "AccordionExtender"

This error doesn't effect that panel on page in live environment only causes error on design view. You can view your panel in design by applying syntax like that:

    <asp:Wizard ID="Wizard1" runat="server" Height="286px" Width="700px" ActiveStepIndex="0"
DisplaySideBar="False" DisplayCancelButton="True" OnFinishButtonClick="Wizard1_FinishButtonClick">
<asp:WizardStep ID="Recipients" runat="server" Title="Recipients" StepType="Start">
<asp:UpdatePanel ID="upOrderBy" runat="server">
<asp:Accordion ID="Accordion1" runat="server" CssClass="accordion" HeaderCssClass="accordionHeader"
HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">
<asp:AccordionPane ID="AccordionPane1" runat="server">
Add Groups</Header>
this is add group content area
<asp:AccordionPane ID="AccordionPane2" runat="server">
Add more Contacts</Header>
this is add contact content area
<asp:WizardStep ID="MessageText" runat="server" Title="Message Text">

Crystal Report doesn't show after some time

If application is in live environment and built using .Net Framework 4.0 along with SQL Server 2008 R2 database. Sometimes problem is rising when crystal report viewer doesn't able to show me on page. No matter how many times you reset iis server or clear sessions. Another weird thing that other pages behave fine with tables from which crystal reports pick the data working perfectly while crystal report doesn't.

One important link to resolve that issue is mentioned below.

Sometimes this link will not help certain peoples, they also mentioned error "Report Load Failed", but if Exception is raising from method means its something is cooking there weird but why that exception not raised when any user hit different reports several time???

The simple solution for above mention issues are :
  1. Please make sure the crsytal report version that you used on your code MATCHES the one you instal on the server.
  2. Please make sure the crsytal report assemblies that you used on your code MATCHES the one you instal on the server.
  3. Please make sure you allow FULL TRUST mode on your site/application.
  4. Please make sure you set the application pool to run under LOCAL SERVICE permission.
  5. Please make sure you copy the crystalreportviewer folder to your working folder.
  6. Please make sure your server has enough RAMs to run Crystal Report.

August 13, 2012

Unabled to view newly inserted row in table

Add new item in my ventory and also create a log file in which each transaction will be recorded. After adding record via store procedure it show me none of row in SQL server database as i also save their newly inserted id into log file and when i select rows according to that id it showed nothing. Let me clearify you that ID is auto generated in database.

If you are sure that your record is well inserted into the db, you can try to do this:

var result = (from e in XXXX
order e by e.Id desc
select e).First();

to see the result.

Jquery response when retrieving Data

Jquery is getting server side data using any of the methods ($.getJSON , $.ajax or $.get) when data is retrieving many sites show some GIf or animation even some show the exact % prgress bar (yahoo email uploading , downloading) how can we encorporate this using jquery how can we know the content lenth dat is coming so that i can put some progress bar or gif animation until the data is complete retrieved.

According to need,

function GetCurrentUser() { 

type: "POST",
url: "TestService.asmx/GetCurrentUser",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccessGetCurrentUser,
error: onError,
beforeSend: startingAjax,
complete: ajaxCompleted,
cache: false
function onSuccessGetCurrentUser(data, status) {

if (data.d != "") {

alert('Employee id: ' + data.d);
function onError(request, status, error) {

var msg = 'Error occoured';
alert('Error: ' + msg);
function startingAjax() {

function ajaxCompleted() {


Where beforeSend is the function to show gif image and complete is the function when your data return in json format.

Read Data from Excel File

How can i read all columns from excel file and then place that columns into my database table using store procedure. I successfully copy all the data from excel file but i am confused how to put that data into database table using store procedure? Is theres any loop required?


public void CreateFromExcel()
FileInfo MyFile = new FileInfo("D:\\MgsData.xls");
string Value = null;
string dgData = null;
FileName = MyFile.Name;

string cnstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + MyFile + ";Extended Properties=Excel 8.0";
OleDbConnection oledbConn = new OleDbConnection(cnstr);

DataTable dtSheet = new DataTable();

dtSheet = oledbConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

//Dim rowscount As Integer = dtSheet.Rows.Count
//Dim RowName As String = dtSheet.Rows("TABLE_NAME").ToString()

foreach (DataRow row in dtSheet.Rows) {
Value = row["TABLE_NAME"].ToString();

string strSQL = "SELECT * FROM [" + Value + "]";

txtTableName.Text = Value.Remove(Value.Length - 1);

OleDbCommand cmd = new OleDbCommand(strSQL, oledbConn);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);


dt = ds.Tables[0];

int rows = dt.Rows.Count - 2;

for (i = 0; i <= rows - 1; i++) {
for (int j = 0; j <= 6; j++) {
dgData = dt.Rows[i][j].ToString();
GridView1.Item(j, i).Value = dgData;

public object Procedure(string ProcedureName)
object functionReturnValue = null;
var _with1 = Declaration;
try { = Connection.GetConnection();
_with1.comm.CommandText = "";
_with1.comm.Connection =;
_with1.comm.CommandType = System.Data.CommandType.StoredProcedure;
_with1.comm.CommandText = ProcedureName;
} catch (Exception ex) {
if (Information.Err().Number != 0)
Interaction.MsgBox(Information.Err().Description, MsgBoxStyle.Critical);
return functionReturnValue;
return functionReturnValue;

public void Lines()
foreach (GridViewRow row in GridView1.Rows) {
Parameters("@TMasterID", SqlDbType.Int, row.Cells(0).Text);
Parameters("@MobileNumber", SqlDbType.VarChar, row.Cells(1).Text);
Parameters("@ModemNumber", SqlDbType.VarChar, row.Cells(2).Text);
Parameters("@PortName", SqlDbType.VarChar, row.Cells(3).Text);


public void Parameters(string Col, System.Data.SqlDbType dType, string Value)
Declaration.comm.Parameters.Add(Col, dType).Value = Value;


Public Sub CreateFromExcel() 
Dim MyFile As FileInfo = New FileInfo("D:\MgsData.xls")
Dim Value, dgData As String
FileName = MyFile.Name

Dim cnstr As String = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" & MyFile & ";Extended Properties=Excel 8.0"
Dim oledbConn As OleDbConnection = New OleDbConnection(cnstr)

Dim dtSheet As DataTable = New DataTable()

dtSheet = oledbConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)

'Dim rowscount As Integer = dtSheet.Rows.Count
'Dim RowName As String = dtSheet.Rows("TABLE_NAME").ToString()

For Each row As DataRow In dtSheet.Rows
Value = row("TABLE_NAME").ToString()

Dim strSQL As String = "SELECT * FROM [" & Value & "]"

txtTableName.Text = Value.Remove(Value.Length - 1)

Dim cmd As OleDbCommand = New OleDbCommand(strSQL, oledbConn)
Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable()
Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)


dt = ds.Tables(0)

Dim rows As Integer = dt.Rows.Count - 2

For i = 0 To rows - 1
For j As Integer = 0 To 6
dgData = dt.Rows(i)(j).ToString
GridView1.Item(j, i).Value = dgData

End Sub
Public Function Procedure(ByVal ProcedureName As String)
With Declaration
.cn = Connection.GetConnection()
.comm.CommandText = ""
.comm.Connection = .cn
.comm.CommandType = Data.CommandType.StoredProcedure
.comm.CommandText = ProcedureName
Catch ex As Exception
If Err.Number <> 0 Then MsgBox(Err.Description, MsgBoxStyle.Critical)
Exit Function
End Try
End With
End Function

Public Sub Lines()
For Each row As GridViewRow In GridView1.Rows
Parameters("@TMasterID", SqlDbType.Int, row.Cells(0).Text )
Parameters("@MobileNumber", SqlDbType.VarChar, row.Cells(1).Text )
Parameters("@ModemNumber", SqlDbType.VarChar, row.Cells(2).Text )
Parameters("@PortName", SqlDbType.Varchar, row.Cells(3).Text )

End Sub

Public Sub Parameters(ByVal Col As String, ByVal dType As Data.SqlDbType, ByVal Value As String)
Declaration.comm.Parameters.Add(Col, dType).Value = Value
End Sub

How to redirect page?

Suppose I am browsing Orders.aspx without login to that website using any credentials, web authenticator treated me as ? user so it redirect me to login page back. After login successfully how can I redirect to my past location from which this redirectional process occurred?

var redirectUrl = Request.QueryString["ReturnUrl"]; 

if (redirectUrl != null)
Response.Redirect(redirectUrl, false);

List of all countries

So many peoples asked on several forums that how can they get list of all countries and make them a list so user can select their desire country. So I have a list of countries and in future, will update this post by adding relation between countries and their respective cities.

<asp:DropDownList ID="ddlCountryList" runat="server"> 
<asp:ListItem Value="-1">Select Country</asp:ListItem>
<asp:ListItem Value="AF">Afghanistan</asp:ListItem>
<asp:ListItem Value="AL">Albania</asp:ListItem>
<asp:ListItem Value="DZ">Algeria</asp:ListItem>
<asp:ListItem Value="AS">American Samoa</asp:ListItem>
<asp:ListItem Value="AD">Andorra</asp:ListItem>
<asp:ListItem Value="AO">Angola</asp:ListItem>
<asp:ListItem Value="AI">Anguilla</asp:ListItem>
<asp:ListItem Value="AQ">Antarctica</asp:ListItem>
<asp:ListItem Value="AG">Antigua And Barbuda</asp:ListItem>
<asp:ListItem Value="AR">Argentina</asp:ListItem>
<asp:ListItem Value="AM">Armenia</asp:ListItem>
<asp:ListItem Value="AW">Aruba</asp:ListItem>
<asp:ListItem Value="AU">Australia</asp:ListItem>
<asp:ListItem Value="AT">Austria</asp:ListItem>
<asp:ListItem Value="AZ">Azerbaijan</asp:ListItem>
<asp:ListItem Value="BS">Bahamas</asp:ListItem>
<asp:ListItem Value="BH">Bahrain</asp:ListItem>
<asp:ListItem Value="BD">Bangladesh</asp:ListItem>
<asp:ListItem Value="BB">Barbados</asp:ListItem>
<asp:ListItem Value="BY">Belarus</asp:ListItem>
<asp:ListItem Value="BE">Belgium</asp:ListItem>
<asp:ListItem Value="BZ">Belize</asp:ListItem>
<asp:ListItem Value="BJ">Benin</asp:ListItem>
<asp:ListItem Value="BM">Bermuda</asp:ListItem>
<asp:ListItem Value="BT">Bhutan</asp:ListItem>
<asp:ListItem Value="BO">Bolivia</asp:ListItem>
<asp:ListItem Value="BA">Bosnia And Herzegowina</asp:ListItem>
<asp:ListItem Value="BW">Botswana</asp:ListItem>
<asp:ListItem Value="BV">Bouvet Island</asp:ListItem>
<asp:ListItem Value="BR">Brazil</asp:ListItem>
<asp:ListItem Value="IO">British Indian Ocean Territory</asp:ListItem>
<asp:ListItem Value="BN">Brunei Darussalam</asp:ListItem>
<asp:ListItem Value="BG">Bulgaria</asp:ListItem>
<asp:ListItem Value="BF">Burkina Faso</asp:ListItem>
<asp:ListItem Value="BI">Burundi</asp:ListItem>
<asp:ListItem Value="KH">Cambodia</asp:ListItem>
<asp:ListItem Value="CM">Cameroon</asp:ListItem>
<asp:ListItem Value="CA">Canada</asp:ListItem>
<asp:ListItem Value="CV">Cape Verde</asp:ListItem>
<asp:ListItem Value="KY">Cayman Islands</asp:ListItem>
<asp:ListItem Value="CF">Central African Republic</asp:ListItem>
<asp:ListItem Value="TD">Chad</asp:ListItem>
<asp:ListItem Value="CL">Chile</asp:ListItem>
<asp:ListItem Value="CN">China</asp:ListItem>
<asp:ListItem Value="CX">Christmas Island</asp:ListItem>
<asp:ListItem Value="CC">Cocos (Keeling) Islands</asp:ListItem>
<asp:ListItem Value="CO">Colombia</asp:ListItem>
<asp:ListItem Value="KM">Comoros</asp:ListItem>
<asp:ListItem Value="CG">Congo</asp:ListItem>
<asp:ListItem Value="CK">Cook Islands</asp:ListItem>
<asp:ListItem Value="CR">Costa Rica</asp:ListItem>
<asp:ListItem Value="CI">Cote D'Ivoire</asp:ListItem>
<asp:ListItem Value="HR">Croatia (Local Name: Hrvatska)</asp:ListItem>
<asp:ListItem Value="CU">Cuba</asp:ListItem>
<asp:ListItem Value="CY">Cyprus</asp:ListItem>
<asp:ListItem Value="CZ">Czech Republic</asp:ListItem>
<asp:ListItem Value="DK">Denmark</asp:ListItem>
<asp:ListItem Value="DJ">Djibouti</asp:ListItem>
<asp:ListItem Value="DM">Dominica</asp:ListItem>
<asp:ListItem Value="DO">Dominican Republic</asp:ListItem>
<asp:ListItem Value="TP">East Timor</asp:ListItem>
<asp:ListItem Value="EC">Ecuador</asp:ListItem>
<asp:ListItem Value="EG">Egypt</asp:ListItem>
<asp:ListItem Value="SV">El Salvador</asp:ListItem>
<asp:ListItem Value="GQ">Equatorial Guinea</asp:ListItem>
<asp:ListItem Value="ER">Eritrea</asp:ListItem>
<asp:ListItem Value="EE">Estonia</asp:ListItem>
<asp:ListItem Value="ET">Ethiopia</asp:ListItem>
<asp:ListItem Value="FK">Falkland Islands (Malvinas)</asp:ListItem>
<asp:ListItem Value="FO">Faroe Islands</asp:ListItem>
<asp:ListItem Value="FJ">Fiji</asp:ListItem>
<asp:ListItem Value="FI">Finland</asp:ListItem>
<asp:ListItem Value="FR">France</asp:ListItem>
<asp:ListItem Value="GF">French Guiana</asp:ListItem>
<asp:ListItem Value="PF">French Polynesia</asp:ListItem>
<asp:ListItem Value="TF">French Southern Territories</asp:ListItem>
<asp:ListItem Value="GA">Gabon</asp:ListItem>
<asp:ListItem Value="GM">Gambia</asp:ListItem>
<asp:ListItem Value="GE">Georgia</asp:ListItem>
<asp:ListItem Value="DE">Germany</asp:ListItem>
<asp:ListItem Value="GH">Ghana</asp:ListItem>
<asp:ListItem Value="GI">Gibraltar</asp:ListItem>
<asp:ListItem Value="GR">Greece</asp:ListItem>
<asp:ListItem Value="GL">Greenland</asp:ListItem>
<asp:ListItem Value="GD">Grenada</asp:ListItem>
<asp:ListItem Value="GP">Guadeloupe</asp:ListItem>
<asp:ListItem Value="GU">Guam</asp:ListItem>
<asp:ListItem Value="GT">Guatemala</asp:ListItem>
<asp:ListItem Value="GN">Guinea</asp:ListItem>
<asp:ListItem Value="GW">Guinea-Bissau</asp:ListItem>
<asp:ListItem Value="GY">Guyana</asp:ListItem>
<asp:ListItem Value="HT">Haiti</asp:ListItem>
<asp:ListItem Value="HM">Heard And McDonald Islands</asp:ListItem>
<asp:ListItem Value="VA">Holy See (Vatican City State)</asp:ListItem>
<asp:ListItem Value="HN">Honduras</asp:ListItem>
<asp:ListItem Value="HK">Hong Kong</asp:ListItem>
<asp:ListItem Value="HU">Hungary</asp:ListItem>
<asp:ListItem Value="IS">Ice Land</asp:ListItem>
<asp:ListItem Value="IN">India</asp:ListItem>
<asp:ListItem Value="ID">Indonesia</asp:ListItem>
<asp:ListItem Value="IR">Iran (Islamic Republic Of)</asp:ListItem>
<asp:ListItem Value="IQ">Iraq</asp:ListItem>
<asp:ListItem Value="IE">Ireland</asp:ListItem>
<asp:ListItem Value="IL">Israel</asp:ListItem>
<asp:ListItem Value="IT">Italy</asp:ListItem>
<asp:ListItem Value="JM">Jamaica</asp:ListItem>
<asp:ListItem Value="JP">Japan</asp:ListItem>
<asp:ListItem Value="JO">Jordan</asp:ListItem>
<asp:ListItem Value="KZ">Kazakhstan</asp:ListItem>
<asp:ListItem Value="KE">Kenya</asp:ListItem>
<asp:ListItem Value="KI">Kiribati</asp:ListItem>
<asp:ListItem Value="KP">Korea, Dem. People's Republic</asp:ListItem>
<asp:ListItem Value="KR">Korea, Republic Of</asp:ListItem>
<asp:ListItem Value="KW">Kuwait</asp:ListItem>
<asp:ListItem Value="KG">Kyrgyzstan</asp:ListItem>
<asp:ListItem Value="LA">Lao People's Dem. Republic</asp:ListItem>
<asp:ListItem Value="LV">Latvia</asp:ListItem>
<asp:ListItem Value="LB">Lebanon</asp:ListItem>
<asp:ListItem Value="LS">Lesotho</asp:ListItem>
<asp:ListItem Value="LR">Liberia</asp:ListItem>
<asp:ListItem Value="LY">Libyan Arab Jamahiriya</asp:ListItem>
<asp:ListItem Value="LI">Liechtenstein</asp:ListItem>
<asp:ListItem Value="LT">Lithuania</asp:ListItem>
<asp:ListItem Value="LU">Luxembourg</asp:ListItem>
<asp:ListItem Value="MO">Macau</asp:ListItem>
<asp:ListItem Value="MK">Macedonia</asp:ListItem>
<asp:ListItem Value="MG">Madagascar</asp:ListItem>
<asp:ListItem Value="MW">Malawi</asp:ListItem>
<asp:ListItem Value="MY">Malaysia</asp:ListItem>
<asp:ListItem Value="MV">Maldives</asp:ListItem>
<asp:ListItem Value="ML">Mali</asp:ListItem>
<asp:ListItem Value="MT">Malta</asp:ListItem>
<asp:ListItem Value="MH">Marshall Islands</asp:ListItem>
<asp:ListItem Value="MQ">Martinique</asp:ListItem>
<asp:ListItem Value="MR">Mauritania</asp:ListItem>
<asp:ListItem Value="MU">Mauritius</asp:ListItem>
<asp:ListItem Value="YT">Mayotte</asp:ListItem>
<asp:ListItem Value="MX">Mexico</asp:ListItem>
<asp:ListItem Value="FM">Micronesia, Federated States</asp:ListItem>
<asp:ListItem Value="MD">Moldova, Republic Of</asp:ListItem>
<asp:ListItem Value="MC">Monaco</asp:ListItem>
<asp:ListItem Value="MN">Mongolia</asp:ListItem>
<asp:ListItem Value="MS">Montserrat</asp:ListItem>
<asp:ListItem Value="MA">Morocco</asp:ListItem>
<asp:ListItem Value="MZ">Mozambique</asp:ListItem>
<asp:ListItem Value="MM">Myanmar</asp:ListItem>
<asp:ListItem Value="NA">Namibia</asp:ListItem>
<asp:ListItem Value="NR">Nauru</asp:ListItem>
<asp:ListItem Value="NP">Nepal</asp:ListItem>
<asp:ListItem Value="NL">Netherlands</asp:ListItem>
<asp:ListItem Value="AN">Netherlands Ant Illes</asp:ListItem>
<asp:ListItem Value="NC">New Caledonia</asp:ListItem>
<asp:ListItem Value="NZ">New Zealand</asp:ListItem>
<asp:ListItem Value="NI">Nicaragua</asp:ListItem>
<asp:ListItem Value="NE">Niger</asp:ListItem>
<asp:ListItem Value="NG">Nigeria</asp:ListItem>
<asp:ListItem Value="NU">Niue</asp:ListItem>
<asp:ListItem Value="NF">Norfolk Island</asp:ListItem>
<asp:ListItem Value="MP">Northern Mariana Islands</asp:ListItem>
<asp:ListItem Value="NO">Norway</asp:ListItem>
<asp:ListItem Value="OM">Oman</asp:ListItem>
<asp:ListItem Value="PK" Selected="True">Pakistan</asp:ListItem>
<asp:ListItem Value="PW">Palau</asp:ListItem>
<asp:ListItem Value="PA">Panama</asp:ListItem>
<asp:ListItem Value="PG">Papua New Guinea</asp:ListItem>
<asp:ListItem Value="PY">Paraguay</asp:ListItem>
<asp:ListItem Value="PE">Peru</asp:ListItem>
<asp:ListItem Value="PH">Philippines</asp:ListItem>
<asp:ListItem Value="PN">Pitcairn</asp:ListItem>
<asp:ListItem Value="PL">Poland</asp:ListItem>
<asp:ListItem Value="PT">Portugal</asp:ListItem>
<asp:ListItem Value="PR">Puerto Rico</asp:ListItem>
<asp:ListItem Value="QA">Qatar</asp:ListItem>
<asp:ListItem Value="RE">Reunion</asp:ListItem>
<asp:ListItem Value="RO">Romania</asp:ListItem>
<asp:ListItem Value="RU">Russian Federation</asp:ListItem>
<asp:ListItem Value="RW">Rwanda</asp:ListItem>
<asp:ListItem Value="KN">Saint Kitts And Nevis</asp:ListItem>
<asp:ListItem Value="LC">Saint Lucia</asp:ListItem>
<asp:ListItem Value="VC">Saint Vincent, The Grenadines</asp:ListItem>
<asp:ListItem Value="WS">Samoa</asp:ListItem>
<asp:ListItem Value="SM">San Marino</asp:ListItem>
<asp:ListItem Value="ST">Sao Tome And Principe</asp:ListItem>
<asp:ListItem Value="SA">Saudi Arabia</asp:ListItem>
<asp:ListItem Value="SN">Senegal</asp:ListItem>
<asp:ListItem Value="SC">Seychelles</asp:ListItem>
<asp:ListItem Value="SL">Sierra Leone</asp:ListItem>
<asp:ListItem Value="SG">Singapore</asp:ListItem>
<asp:ListItem Value="SK">Slovakia (Slovak Republic)</asp:ListItem>
<asp:ListItem Value="SI">Slovenia</asp:ListItem>
<asp:ListItem Value="SB">Solomon Islands</asp:ListItem>
<asp:ListItem Value="SO">Somalia</asp:ListItem>
<asp:ListItem Value="ZA">South Africa</asp:ListItem>
<asp:ListItem Value="GS">South Georgia , S Sandwich Is.</asp:ListItem>
<asp:ListItem Value="ES">Spain</asp:ListItem>
<asp:ListItem Value="LK">Sri Lanka</asp:ListItem>
<asp:ListItem Value="SH">St. Helena</asp:ListItem>
<asp:ListItem Value="PM">St. Pierre And Miquelon</asp:ListItem>
<asp:ListItem Value="SD">Sudan</asp:ListItem>
<asp:ListItem Value="SR">Suriname</asp:ListItem>
<asp:ListItem Value="SJ">Svalbard, Jan Mayen Islands</asp:ListItem>
<asp:ListItem Value="SZ">Swaziland</asp:ListItem>
<asp:ListItem Value="SE">Sweden</asp:ListItem>
<asp:ListItem Value="CH">Switzerland</asp:ListItem>
<asp:ListItem Value="SY">Syrian Arab Republic</asp:ListItem>
<asp:ListItem Value="TW">Taiwan</asp:ListItem>
<asp:ListItem Value="TJ">Tajikistan</asp:ListItem>
<asp:ListItem Value="TZ">Tanzania, United Republic Of</asp:ListItem>
<asp:ListItem Value="TH">Thailand</asp:ListItem>
<asp:ListItem Value="TG">Togo</asp:ListItem>
<asp:ListItem Value="TK">Tokelau</asp:ListItem>
<asp:ListItem Value="TO">Tonga</asp:ListItem>
<asp:ListItem Value="TT">Trinidad And Tobago</asp:ListItem>
<asp:ListItem Value="TN">Tunisia</asp:ListItem>
<asp:ListItem Value="TR">Turkey</asp:ListItem>
<asp:ListItem Value="TM">Turkmenistan</asp:ListItem>
<asp:ListItem Value="TC">Turks And Caicos Islands</asp:ListItem>
<asp:ListItem Value="TV">Tuvalu</asp:ListItem>
<asp:ListItem Value="UG">Uganda</asp:ListItem>
<asp:ListItem Value="UA">Ukraine</asp:ListItem>
<asp:ListItem Value="AE">United Arab Emirates</asp:ListItem>
<asp:ListItem Value="GB">United Kingdom</asp:ListItem>
<asp:ListItem Value="US">United States</asp:ListItem>
<asp:ListItem Value="UM">United States Minor Is.</asp:ListItem>
<asp:ListItem Value="UY">Uruguay</asp:ListItem>
<asp:ListItem Value="UZ">Uzbekistan</asp:ListItem>
<asp:ListItem Value="VU">Vanuatu</asp:ListItem>
<asp:ListItem Value="VE">Venezuela</asp:ListItem>
<asp:ListItem Value="VN">Viet Nam</asp:ListItem>
<asp:ListItem Value="VG">Virgin Islands (British)</asp:ListItem>
<asp:ListItem Value="VI">Virgin Islands (U.S.)</asp:ListItem>
<asp:ListItem Value="WF">Wallis And Futuna Islands</asp:ListItem>
<asp:ListItem Value="EH">Western Sahara</asp:ListItem>
<asp:ListItem Value="YE">Yemen</asp:ListItem>
<asp:ListItem Value="YU">Yugoslavia</asp:ListItem>
<asp:ListItem Value="ZR">Zaire</asp:ListItem>
<asp:ListItem Value="ZM">Zambia</asp:ListItem>
<asp:ListItem Value="ZW">Zimbabwe</asp:ListItem>

How to send email from html page ?

Sending email is a very common task in any web application. In almost every web application, their will atleast be an occassion to send email in any fashion. To send an email from html page using php is quite easy then framework. I'll show you how this makes easier :)

Sending a Simple Text Email

//define the receiver of the email
$to = '';
//define the subject of the email
$subject = 'Test email';
//define the message to be sent. Each line should be separated with \n
$message = "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:\r\nReply-To:";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

Sending HTML Email

//define the receiver of the email
$to = '';
//define the subject of the email
$subject = 'Test HTML email';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:\r\nReply-To:";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
//define the body of the message.
ob_start(); //Turn on output buffering
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!

This is something with HTML formatting.

//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

Sending Email with Attachment

//define the receiver of the email
$to = '';
//define the subject of the email
$subject = 'Test email with attachment';
//create a boundary string. It must be unique
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time()));
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From:\r\nReply-To:";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
$attachment = chunk_split(base64_encode(file_get_contents('')));
//define the body of the message.
ob_start(); //Turn on output buffering
Content-Type: multipart/alternative; boundary="PHP-alt-"

Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!!!
This is simple text email message.

Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

Hello World!

This is something with HTML formatting.


Content-Type: application/zip; name=""
Content-Transfer-Encoding: base64
Content-Disposition: attachment


//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
echo $mail_sent ? "Mail sent" : "Mail failed";

Hope these codes will help you.