Archive

Archive for December, 2011

Google Weather with ASP.Net

December 27, 2011 Leave a comment

Hi all,

try this example to user Google Weather with ASP.Net

Now we will Create a Method to get Weather for Location


public static void GoogleWeather(string location)
 {
 HttpWebRequest GoogleRequest;
 HttpWebResponse GoogleResponse = null;
 XmlDocument GoogleXMLdoc = null;
 try
 {
 GoogleRequest = (HttpWebRequest)WebRequest.Create("http://www.google.com/ig/api?weather=" + string.Format(location));
 GoogleResponse = (HttpWebResponse)GoogleRequest.GetResponse();
 GoogleXMLdoc = new XmlDocument();
 GoogleXMLdoc.Load(GoogleResponse.GetResponseStream());
 XmlNode root = GoogleXMLdoc.DocumentElement;
 XmlNodeList nodeList1 = root.SelectNodes("weather/forecast_information");
 HttpContext.Current.Response.Write("<B>City : " + nodeList1.Item(0).SelectSingleNode("city").Attributes["data"].InnerText + "</B>");
 XmlNodeList nodeList = root.SelectNodes("weather/current_conditions");
 HttpContext.Current.Response.Write("<TABLE cellPadding=5><TBODY><TR>");
 HttpContext.Current.Response.Write("<TD><B><BIG><NOBR>" + nodeList.Item(0).SelectSingleNode("temp_c").Attributes["data"].InnerText + " °C | " + nodeList.Item(0).SelectSingleNode("temp_f").Attributes["data"].InnerText + " °F</NOBR></BIG></B>");
 HttpContext.Current.Response.Write("<B>Current:</B> " + nodeList.Item(0).SelectSingleNode("condition").Attributes["data"].InnerText + "");
 HttpContext.Current.Response.Write("" + nodeList.Item(0).SelectSingleNode("wind_condition").Attributes["data"].InnerText + "");
 HttpContext.Current.Response.Write(nodeList.Item(0).SelectSingleNode("humidity").Attributes["data"].InnerText);
 nodeList = root.SelectNodes("descendant::weather/forecast_conditions");
 foreach (XmlNode nod in nodeList)
 {
 HttpContext.Current.Response.Write("</TD><TD align=middle>" + nod.SelectSingleNode("day_of_week").Attributes["data"].InnerText + "");
 HttpContext.Current.Response.Write("<IMG alt='" + nod.SelectSingleNode("condition").Attributes["data"].InnerText + "' src='http://www.google.com" + nod.SelectSingleNode("icon").Attributes["data"].InnerText + "'>");
 HttpContext.Current.Response.Write(nod.SelectSingleNode("low").Attributes["data"].InnerText + "°F | ");
 HttpContext.Current.Response.Write(nod.SelectSingleNode("high").Attributes["data"].InnerText + "°F");
 }
 HttpContext.Current.Response.Write("</TD></TR></TBODY></TABLE>");
 }
 catch (System.Exception ex)
 {
 HttpContext.Current.Response.Write(ex.Message);
 }
 finally
 {
 GoogleResponse.Close();
 }
 }

To use this method :-

GoogleWeather("Egypt");

Hope this helps

Good Luck

Categories: ASP.Net

JQuery to Enable and Disable Textbox when CheckBox is Checked with Gridview

December 19, 2011 4 comments

Hi all,

try this example to use JQuery to Enable and Disable Textbox when CheckBox is Checked with Gridview

1) Open VS2008 and create a new website and add new page and from Toolbox drag Gridview in web page so our page will be like this :-


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
 <Columns>
 <asp:TemplateField HeaderText="Ministry">
 <ItemTemplate>
 <asp:CheckBox ID="CheckBox" runat="server" />
 </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Ministry">
 <ItemTemplate>
 <asp:Label ID="Ministry" runat="server" Text='<%#Eval("Ministry")%>' />
 </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Title">
 <ItemTemplate>
 <asp:Label ID="Title" runat="server" Text='<%#Eval("Title")%>' />
 </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Criteria">
 <ItemTemplate>
 <asp:TextBox ID="Criteria" runat="server" Text='<%#Eval("Criteria")%>' />
 </ItemTemplate>
 </asp:TemplateField>
 </Columns>
 </asp:GridView>

2) Now we need to Bind Grivdview control so in code behind add the following code :-


protected void Page_Load(object sender, EventArgs e)
 {
 string s = Guid.NewGuid().ToString().ToLower();
 var obj = new { Ministry = "Ministry 0", Title = "Title 0", Criteria = "Criteria 0" };
 var objList = (new[] { obj }).ToList();
 objList.Add(new { Ministry = "Minis try 1", Title = "Title 1", Criteria = "Criteria 1" });
 objList.Add(new { Ministry = "Mi nis try sfd 2", Title = "Title 2", Criteria = "Criteria 2" });
 objList.Add(new { Ministry = "Minis try fdsf sdf 3", Title = "Title 3", Criteria = "Criteria 3" });
 objList.Add(new { Ministry = "Mini stryd dd 4", Title = "Title 4", Criteria = "Criteria 4" });
 objList.Add(new { Ministry = "Min is tryf 5", Title = "Title 5", Criteria = "Criteria 5" });
 objList.Add(new { Ministry = "Mini stry 6", Title = "Title 6", Criteria = "Criteria 6" });
 GridView1.DataSource = objList;
 GridView1.DataBind();
 }

3) Now We need to add Jquery function which will enable and disable Textbox in Gridview according to Checkbox state


<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function() {
 $("input[type=text][id*=Criteria]").attr("disabled", true);
 $("input[type=checkbox][id*=CheckBox]").click(function() {
 if (this.checked)
 $(this).closest("tr").find("input[type=text][id*=Criteria]").attr("disabled", false);
 else
 $(this).closest("tr").find("input[type=text][id*=Criteria]").attr("disabled", true);
 });
 });

 </script>

Hope this helps

Good Luck

Categories: ASP.Net, Jquery

Encrypt and Decrypt QueryString in Gridview

December 9, 2011 Leave a comment

Hi all,

try this example to Encrypt and Decrypt QueryString in Gridview

In this example i will use Northwind Database (Categories and Products tables)

1) Open VS2008 and create new web site

2) Add Web.Config and add the connection string to database


<connectionStrings>
 <add name="NorthwindConnectionString" connectionString="Data Source=.;Initial Catalog=Northwind;Integrated Security=True" providerName="System.Data.SqlClient"/>
 </connectionStrings>

3) Add new Class name it “Encriptor.cs” and add the following code which will Encrypt and Decrypt Querystring :-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.IO;
using System.Text;

/// <summary>
/// Summary description for Encriptor
/// </summary>
public class Encriptor
{
 public Encriptor()
 {
 }

const string DESKey = "AQWSEDRF";
 public static int key = 129;

public static string Encrypt(string strToEncrypt, string strKey)
 {
 try
 {
 TripleDESCryptoServiceProvider objDESCrypto =
 new TripleDESCryptoServiceProvider();
 MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
 byte[] byteHash, byteBuff;
 string strTempKey = strKey;
 byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
 objHashMD5 = null;
 objDESCrypto.Key = byteHash;
 objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
 byteBuff = ASCIIEncoding.ASCII.GetBytes(strToEncrypt);
 return Convert.ToBase64String(objDESCrypto.CreateEncryptor().
 TransformFinalBlock(byteBuff, 0, byteBuff.Length));
 }
 catch (Exception ex)
 {
 return "Wrong Input. " + ex.Message;
 }
 }

/// <summary>
 /// Decrypt the given string using the specified key.
 /// </summary>
 /// <param name="strEncrypted">The string to be decrypted.</param>
 /// <param name="strKey">The decryption key.</param>
 /// <returns>The decrypted string.</returns>
 public static string Decrypt(string strEncrypted, string strKey)
 {
 try
 {
 TripleDESCryptoServiceProvider objDESCrypto =
 new TripleDESCryptoServiceProvider();
 MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
 byte[] byteHash, byteBuff;
 string strTempKey = strKey;
 byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
 objHashMD5 = null;
 objDESCrypto.Key = byteHash;
 objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
 byteBuff = Convert.FromBase64String(strEncrypted);
 string strDecrypted = ASCIIEncoding.ASCII.GetString
 (objDESCrypto.CreateDecryptor().TransformFinalBlock
 (byteBuff, 0, byteBuff.Length));
 objDESCrypto = null;
 return strDecrypted;
 }
 catch (Exception ex)
 {
 return "Wrong Input. " + ex.Message;
 }
 }

public static string decryptQueryString(string stringToDecrypt)//Decrypt the content
 {
 byte[] c = Convert.FromBase64String(stringToDecrypt);
 string decryptedConnectionString = System.Text.UTF32Encoding.UTF32.GetString(c);
 decryptedConnectionString = decryptedConnectionString.Replace("_V_", " ");
 return decryptedConnectionString;
 return stringToDecrypt;
 return Decrypt(stringToDecrypt, DESKey);
 }

public static string Reverse(string str)
 {
 int len = str.Length;
 char[] arr = new char[len];
 for (int i = 0; i < len; i++)
 {
 arr[i] = str[len - 1 - i];
 }
 return new string(arr);
 }

public static string ReverseAdvanced(string str, bool isenc)
 {
 string result = Reverse(str);
 if (!(str.Length < 3))
 {
 for (int i = 0; i < str.Length; i++)
 {
 ShiftMiddle(result, isenc);
 }
 }
 return result;
 }
 public static string encryptQueryString(string stringToEncrypt)// Encrypt the content
 {
 stringToEncrypt = stringToEncrypt.Replace(" ", "_V_");
 byte[] b = System.Text.UTF32Encoding.UTF32.GetBytes(stringToEncrypt);
 string encryptedConnectionString = Convert.ToBase64String(b);
 return encryptedConnectionString;
 return stringToEncrypt;
 return Encrypt(stringToEncrypt, DESKey);
 return stringToEncrypt + "x";
 }

static byte[] Convert2ByteArray(string strInput)
 {
 int intCounter; char[] arrChar;
 arrChar = strInput.ToCharArray();
 byte[] arrByte = new byte[arrChar.Length];

for (intCounter = 0; intCounter <= arrByte.Length - 1; intCounter++)
 arrByte[intCounter] = Convert.ToByte(arrChar[intCounter]);
 return arrByte;
 }
}

4) Add new Web Page and from Toolbox drag Gridview control


<div>
 <asp:GridView ID="GV_Category" runat="server" AutoGenerateColumns="False"
 DataKeyNames="CategoryID" CellPadding="4" ForeColor="#333333">
 <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
 <Columns>
 <asp:BoundField DataField="CategoryID" HeaderText="CategoryID" ReadOnly="true" InsertVisible="False"
 SortExpression="CategoryID" />
 <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" />
 <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
 <asp:TemplateField>
 <ItemTemplate>
 <a href="#" onclick="window.open('Product_Detail.aspx?CategoryID=<%# Encriptor.encryptQueryString(DataBinder.Eval(Container.DataItem,"CategoryID").ToString())%>'); return false">Products Detail</a>
 </ItemTemplate>
 </asp:TemplateField>
 </Columns>
 <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
 <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
 <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
 <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
 <AlternatingRowStyle BackColor="White" />
 </asp:GridView>
 </div>

5)  Now we want to bind that Gridview to Categories table so in code behind we will add the following code :-


protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
 SqlCommand comm = new SqlCommand("Select * from Categories", conn);
 DataSet ds = new DataSet();
 SqlDataAdapter adpter = new SqlDataAdapter(comm);
 adpter.Fill(ds);
 GV_Category.DataSource = ds;
 GV_Category.DataBind();
 }
 }

Don’t forget to use the following Namespace

using System.Data.SqlClient;

6) Add Another Web Page called “Product_Detail.aspx” and from Toolbox drag Gridview control to bind Products for each Category using Querystring


<div>
 <asp:GridView ID="gvProducts" runat="server"
 CssClass="datagrid" AutoGenerateColumns="False"
 DataKeyNames="ProductID" CellPadding="4" ForeColor="#333333">
 <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
 <Columns>
 <asp:BoundField DataField="ProductID" HeaderText="ProductID" ReadOnly="true"
 InsertVisible="False" SortExpression="ProductID" />
 <asp:BoundField DataField="ProductName" HeaderText="ProductName"
 SortExpression="ProductName" />
 <asp:BoundField DataField="QuantityPerUnit" HeaderText="QuantityPerUnit"
 SortExpression="QuantityPerUnit" />
 <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice"
 SortExpression="UnitPrice" />
 </Columns>
 <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
 <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
 <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
 <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
 <AlternatingRowStyle BackColor="White" />
 </asp:GridView>
 </div>

7) In Code behind we will add the following Code :-


protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
 SqlCommand comm = new SqlCommand("Select * from Products where CategoryID = @CategoryID", conn);
 comm.Parameters.Add("@CategoryID", SqlDbType.Int).Value = Encriptor.decryptQueryString(Request.QueryString["CategoryID"]);
 DataSet ds = new DataSet();
 SqlDataAdapter adpter = new SqlDataAdapter(comm);
 adpter.Fill(ds);
 gvProducts.DataSource = ds;
 gvProducts.DataBind();
 }
 }

Hope this helps

Good Luck

Categories: ASP.Net

AJAX Currency Converter with ASP.NET, jQuery and Google

December 3, 2011 2 comments

Hi all ,

try this example to use JQuery and Google to create currency converter with ASP.Net

1) Open VS2008 and create a new web site and add new WebService called “WebService.asmx”

and in code behind add the following code :-


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Text.RegularExpressions;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
 [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {

public WebService () {

 }

[WebMethod]
 public decimal Convert(decimal amount, string fromCurrency, string toCurrency)
 {
 WebClient web = new WebClient();
 string url = string.Format("http://www.google.com/ig/calculator?hl=en&q={2}{0}%3D%3F{1}", fromCurrency.ToUpper(), toCurrency.ToUpper(), amount);
 string response = web.DownloadString(url);
 Regex regex = new Regex("rhs: \\\"(\\d*.\\d*)");
 decimal rate = System.Convert.ToDecimal(regex.Match(response).Groups[1].Value);
 return rate;
 }
}

2) Add new Web Page


<div style="overflow:hidden; padding:10px; width:700px; margin:10px; background:#EAEAFF; border:solid 1px #ccc;">
 <div style="padding: 2px; margin: 2px; float: left;">
 Amount:&nbsp;
 <input id="a" maxlength="12" size="5" value="1" />
 </div>
 <div style="padding: 2px; margin: 2px; float: left;">
 From:&nbsp;
 <select id="from">
 <option value="AED">United Arab Emirates Dirham (AED)</option>
 <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
 <option value="ARS">Argentine Peso (ARS)</option>
 <option value="AUD">Australian Dollar (AUD)</option>
 <option value="BDT">Bangladeshi Taka (BDT)</option>
 <option value="BGN">Bulgarian Lev (BGN)</option>
 <option value="BHD">Bahraini Dinar (BHD)</option>
 <option value="BND">Brunei Dollar (BND)</option>
 <option value="BOB">Bolivian Boliviano (BOB)</option>
 <option value="BRL">Brazilian Real (BRL)</option>
 <option value="BWP">Botswanan Pula (BWP)</option>
 <option value="CAD">Canadian Dollar (CAD)</option>
 <option value="CHF">Swiss Franc (CHF)</option>
 <option value="CLP">Chilean Peso (CLP)</option>
 <option value="CNY">Chinese Yuan (CNY)</option>
 <option value="COP">Colombian Peso (COP)</option>
 <option value="CRC">Costa Rican Colón (CRC)</option>
 <option value="CZK">Czech Republic Koruna (CZK)</option>
 <option value="DKK">Danish Krone (DKK)</option>
 <option value="DOP">Dominican Peso (DOP)</option>
 <option value="DZD">Algerian Dinar (DZD)</option>
 <option value="EEK">Estonian Kroon (EEK)</option>
 <option value="EGP">Egyptian Pound (EGP)</option>
 <option value="EUR">Euro (EUR)</option>
 <option value="FJD">Fijian Dollar (FJD)</option>
 <option value="GBP">British Pound Sterling (GBP)</option>
 <option value="HKD">Hong Kong Dollar (HKD)</option>
 <option value="HNL">Honduran Lempira (HNL)</option>
 <option value="HRK">Croatian Kuna (HRK)</option>
 <option value="HUF">Hungarian Forint (HUF)</option>
 <option value="IDR">Indonesian Rupiah (IDR)</option>
 <option value="ILS">Israeli New Sheqel (ILS)</option>
 <option value="INR">Indian Rupee (INR)</option>
 <option value="JMD">Jamaican Dollar (JMD)</option>
 <option value="JOD">Jordanian Dinar (JOD)</option>
 <option value="JPY">Japanese Yen (JPY)</option>
 <option value="KES">Kenyan Shilling (KES)</option>
 <option value="KRW">South Korean Won (KRW)</option>
 <option value="KWD">Kuwaiti Dinar (KWD)</option>
 <option value="KYD">Cayman Islands Dollar (KYD)</option>
 <option value="KZT">Kazakhstani Tenge (KZT)</option>
 <option value="LBP">Lebanese Pound (LBP)</option>
 <option value="LKR">Sri Lankan Rupee (LKR)</option>
 <option value="LTL">Lithuanian Litas (LTL)</option>
 <option value="LVL">Latvian Lats (LVL)</option>
 <option value="MAD">Moroccan Dirham (MAD)</option>
 <option value="MDL">Moldovan Leu (MDL)</option>
 <option value="MKD">Macedonian Denar (MKD)</option>
 <option value="MUR">Mauritian Rupee (MUR)</option>
 <option value="MVR">Maldivian Rufiyaa (MVR)</option>
 <option value="MXN">Mexican Peso (MXN)</option>
 <option value="MYR">Malaysian Ringgit (MYR)</option>
 <option value="NAD">Namibian Dollar (NAD)</option>
 <option value="NGN">Nigerian Naira (NGN)</option>
 <option value="NIO">Nicaraguan Córdoba (NIO)</option>
 <option value="NOK">Norwegian Krone (NOK)</option>
 <option value="NPR">Nepalese Rupee (NPR)</option>
 <option value="NZD">New Zealand Dollar (NZD)</option>
 <option value="OMR">Omani Rial (OMR)</option>
 <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
 <option value="PGK">Papua New Guinean Kina (PGK)</option>
 <option value="PHP">Philippine Peso (PHP)</option>
 <option value="PKR">Pakistani Rupee (PKR)</option>
 <option value="PLN">Polish Zloty (PLN)</option>
 <option value="PYG">Paraguayan Guarani (PYG)</option>
 <option value="QAR">Qatari Rial (QAR)</option>
 <option value="RON">Romanian Leu (RON)</option>
 <option value="RSD">Serbian Dinar (RSD)</option>
 <option value="RUB">Russian Ruble (RUB)</option>
 <option value="SAR">Saudi Riyal (SAR)</option>
 <option value="SCR">Seychellois Rupee (SCR)</option>
 <option value="SEK">Swedish Krona (SEK)</option>
 <option value="SGD">Singapore Dollar (SGD)</option>
 <option value="SKK">Slovak Koruna (SKK)</option>
 <option value="SLL">Sierra Leonean Leone (SLL)</option>
 <option value="SVC">Salvadoran Colón (SVC)</option>
 <option value="THB">Thai Baht (THB)</option>
 <option value="TND">Tunisian Dinar (TND)</option>
 <option value="TRY">Turkish Lira (TRY)</option>
 <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
 <option value="TWD">New Taiwan Dollar (TWD)</option>
 <option value="TZS">Tanzanian Shilling (TZS)</option>
 <option value="UAH">Ukrainian Hryvnia (UAH)</option>
 <option value="UGX">Ugandan Shilling (UGX)</option>
 <option value="USD">US Dollar (USD)</option>
 <option value="UYU">Uruguayan Peso (UYU)</option>
 <option value="UZS">Uzbekistan Som (UZS)</option>
 <option value="VEF">Venezuelan Bolívar (VEF)</option>
 <option value="VND">Vietnamese Dong (VND)</option>
 <option value="XOF">CFA Franc BCEAO (XOF)</option>
 <option value="YER">Yemeni Rial (YER)</option>
 <option value="ZAR">South African Rand (ZAR)</option>
 <option value="ZMK">Zambian Kwacha (ZMK)</option>
 </select>
 </div>
 <div style="padding: 2px; margin: 2px;">
 to: &nbsp;
 <select id="to">
 <option value="AED">United Arab Emirates Dirham (AED)</option>
 <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
 <option value="ARS">Argentine Peso (ARS)</option>
 <option value="AUD">Australian Dollar (AUD)</option>
 <option value="BDT">Bangladeshi Taka (BDT)</option>
 <option value="BGN">Bulgarian Lev (BGN)</option>
 <option value="BHD">Bahraini Dinar (BHD)</option>
 <option value="BND">Brunei Dollar (BND)</option>
 <option value="BOB">Bolivian Boliviano (BOB)</option>
 <option value="BRL">Brazilian Real (BRL)</option>
 <option value="BWP">Botswanan Pula (BWP)</option>
 <option value="CAD">Canadian Dollar (CAD)</option>
 <option value="CHF">Swiss Franc (CHF)</option>
 <option value="CLP">Chilean Peso (CLP)</option>
 <option value="CNY">Chinese Yuan (CNY)</option>
 <option value="COP">Colombian Peso (COP)</option>
 <option value="CRC">Costa Rican Colón (CRC)</option>
 <option value="CZK">Czech Republic Koruna (CZK)</option>
 <option value="DKK">Danish Krone (DKK)</option>
 <option value="DOP">Dominican Peso (DOP)</option>
 <option value="DZD">Algerian Dinar (DZD)</option>
 <option value="EEK">Estonian Kroon (EEK)</option>
 <option value="EGP">Egyptian Pound (EGP)</option>
 <option value="EUR">Euro (EUR)</option>
 <option value="FJD">Fijian Dollar (FJD)</option>
 <option value="GBP">British Pound Sterling (GBP)</option>
 <option value="HKD">Hong Kong Dollar (HKD)</option>
 <option value="HNL">Honduran Lempira (HNL)</option>
 <option value="HRK">Croatian Kuna (HRK)</option>
 <option value="HUF">Hungarian Forint (HUF)</option>
 <option value="IDR">Indonesian Rupiah (IDR)</option>
 <option value="ILS">Israeli New Sheqel (ILS)</option>
 <option value="INR">Indian Rupee (INR)</option>
 <option value="JMD">Jamaican Dollar (JMD)</option>
 <option value="JOD">Jordanian Dinar (JOD)</option>
 <option value="JPY">Japanese Yen (JPY)</option>
 <option value="KES">Kenyan Shilling (KES)</option>
 <option value="KRW">South Korean Won (KRW)</option>
 <option value="KWD">Kuwaiti Dinar (KWD)</option>
 <option value="KYD">Cayman Islands Dollar (KYD)</option>
 <option value="KZT">Kazakhstani Tenge (KZT)</option>
 <option value="LBP">Lebanese Pound (LBP)</option>
 <option value="LKR">Sri Lankan Rupee (LKR)</option>
 <option value="LTL">Lithuanian Litas (LTL)</option>
 <option value="LVL">Latvian Lats (LVL)</option>
 <option value="MAD">Moroccan Dirham (MAD)</option>
 <option value="MDL">Moldovan Leu (MDL)</option>
 <option value="MKD">Macedonian Denar (MKD)</option>
 <option value="MUR">Mauritian Rupee (MUR)</option>
 <option value="MVR">Maldivian Rufiyaa (MVR)</option>
 <option value="MXN">Mexican Peso (MXN)</option>
 <option value="MYR">Malaysian Ringgit (MYR)</option>
 <option value="NAD">Namibian Dollar (NAD)</option>
 <option value="NGN">Nigerian Naira (NGN)</option>
 <option value="NIO">Nicaraguan Córdoba (NIO)</option>
 <option value="NOK">Norwegian Krone (NOK)</option>
 <option value="NPR">Nepalese Rupee (NPR)</option>
 <option value="NZD">New Zealand Dollar (NZD)</option>
 <option value="OMR">Omani Rial (OMR)</option>
 <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
 <option value="PGK">Papua New Guinean Kina (PGK)</option>
 <option value="PHP">Philippine Peso (PHP)</option>
 <option value="PKR">Pakistani Rupee (PKR)</option>
 <option value="PLN">Polish Zloty (PLN)</option>
 <option value="PYG">Paraguayan Guarani (PYG)</option>
 <option value="QAR">Qatari Rial (QAR)</option>
 <option value="RON">Romanian Leu (RON)</option>
 <option value="RSD">Serbian Dinar (RSD)</option>
 <option value="RUB">Russian Ruble (RUB)</option>
 <option value="SAR">Saudi Riyal (SAR)</option>
 <option value="SCR">Seychellois Rupee (SCR)</option>
 <option value="SEK">Swedish Krona (SEK)</option>
 <option value="SGD">Singapore Dollar (SGD)</option>
 <option value="SKK">Slovak Koruna (SKK)</option>
 <option value="SLL">Sierra Leonean Leone (SLL)</option>
 <option value="SVC">Salvadoran Colón (SVC)</option>
 <option value="THB">Thai Baht (THB)</option>
 <option value="TND">Tunisian Dinar (TND)</option>
 <option value="TRY">Turkish Lira (TRY)</option>
 <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
 <option value="TWD">New Taiwan Dollar (TWD)</option>
 <option value="TZS">Tanzanian Shilling (TZS)</option>
 <option value="UAH">Ukrainian Hryvnia (UAH)</option>
 <option value="UGX">Ugandan Shilling (UGX)</option>
 <option value="USD">US Dollar (USD)</option>
 <option value="UYU">Uruguayan Peso (UYU)</option>
 <option value="UZS">Uzbekistan Som (UZS)</option>
 <option value="VEF">Venezuelan Bolívar (VEF)</option>
 <option value="VND">Vietnamese Dong (VND)</option>
 <option value="XOF">CFA Franc BCEAO (XOF)</option>
 <option value="YER">Yemeni Rial (YER)</option>
 <option value="ZAR">South African Rand (ZAR)</option>
 <option value="ZMK">Zambian Kwacha (ZMK)</option>
 </select>
 </div>
 <br />
 <div style="padding: 2px; margin: 2px; float: left;">
 <input id="submit" type="button" value="Convert" />
 </div>
 <div id="results" style="padding: 2px; margin: 5px;">
 </div>
</div>

and add the following Javascript :-


<script src="jquery-1.6.2.min.js" type="text/javascript"></script>
 <script type="text/javascript">
 $(document).ready(function() {
 $('#submit').click(function() {
 var amount = $('#a').val();
 var from = $('#from').val();
 var to = $('#to').val();
 var params = "http://www.google.com/finance/converter?a=" + amount + "&from=" + from + "&to=" + to;

$.ajax({ type: "POST",
 url: "WebService.asmx/Convert",
 data: "{amount:" + amount + ",fromCurrency:'" + from + "',toCurrency:'" + to + "'}",
 contentType: "application/json; charset=utf-8",
 dataType: "json",
 success: function(data) {
 $('#results').html(data.d);
 }
 });
 });
 });
 </script>

Hope this helps

Good Luck

Categories: ASP.Net, Javascript, Jquery

Enlarge Image on MouseOver in ASP.Net using JQuery

December 3, 2011 Leave a comment

Hi all try this example to enlarge image on mouseover in asp.net using jquery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Img_Enlarge.aspx.cs" Inherits="Img_Enlarge" %>
<!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></title>
 <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
 <style type="text/css">
 .thumbnail
 {
 height: 100px;
 width: 100px;
 position: relative;
 }
 .image
 {
 position: relative;
 width: 400px;
 height: 250px;
 }
 </style>
 <script language="javascript" type="text/javascript">
 $(document).ready(function () {
 $(".thumbnail").mouseover(function () {
 $(".thumbnail").css("opacity", ".5");
 $(this).animate({ opacity: 1.0 });
 $("#imgContainer").append("<img class='image' src='" + $(this).attr("src") + "' />");

});
 $(".thumbnail").mouseout(function () {
 $(".thumbnail").css("opacity", "1.0");
 $(".image").remove();
 });
 });

 </script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 </div>
 </form>
 <div align="center">
 <img class="thumbnail" src="Images/Tree.jpg" alt="" />
 <img class="thumbnail" src="Images/dock.jpg" alt="" />
 <img class="thumbnail" src="Images/forest.jpg" alt="" />
 <img class="thumbnail" src="Images/garden.jpg" alt="" />
 <div id="imgContainer">
 </div>
 </div>
</body>
</html>

If we want to apply it with Image from Database

In ASPX Page :-


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

<!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>AJAX Photo Gallery</title>
 <script src="jquery-1.1.4.js" type="text/javascript"></script>
 <style type="text/css">
 .thumbnail
 {
 height: 100px;
 width: 100px;
 position: relative;
 }
 .image
 {
 position: relative;
 width: 400px;
 height: 250px;
 }
 </style>
 <script language="javascript" type="text/javascript">
 $(document).ready(function () {
 $(".thumbnail").mouseover(function () {
 $(".thumbnail").css("opacity", ".5");
 $(this).animate({ opacity: 1.0 });
 $("#imgContainer").append("<img class='image' src='" + $(this).attr("src") + "' />");
 });
 $(".thumbnail").mouseout(function () {
 $(".thumbnail").css("opacity", "1.0");
 $(".image").remove();
 });
 });
 </script>
</head>
<body>
 <asp:Repeater ID="Repeater1" runat="server">
 <ItemTemplate>
 <img src='<%# Eval("ImagePath") %>' alt="" class="thumbnail" />
 </ItemTemplate>
 </asp:Repeater>
 <div id="imgContainer">
 </div>
</body>
</html>

and In code behind :-


protected void Page_Load(object sender, EventArgs e)
 {
 var list = (new[] { new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/1.jpg", Value = "1" } }).ToList();
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/2.jpg", Value = "2" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/3.jpg", Value = "3" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/4.jpg", Value = "4" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/5.jpg", Value = "5" });
 Repeater1.DataSource = list;
 Repeater1.DataBind();
 }

Hope this helps

Good Luck

 

Categories: ASP.Net, Jquery