Sunday, August 18, 2013

Code for google map - asp.net

1.jscript on top master page

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=abcdefg&sensor=true_or_false"
        type="text/javascript"></script>

    <script type="text/javascript">

    function initialize() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng("<%=_latitude%>","<%=_longtitude%>"), 13);
        map.setUIToDefault();
      }
    }


    </script>


2.jscript on bottom master page

<script language="javascript" type="text/javascript">
GUnload();
initialize();  
</script>


3.delaring div in master page html source

<div id="map_canvas" style="width: 293px; height: 226px">
                                        </div>

function before page load im master page code page

public decimal _latitude, _longtitude;
  
function in page load of master page

 _latitude = Convert.ToDecimal(9.583333);
        _longtitude = Convert.ToDecimal(76.516667);



Textbox to file and file to textbox conversions in asp.net

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;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {//code to convert text in a textbox to a file
        TextWriter w = File.CreateText(Server.MapPath("folder/s.xml"));
        w.WriteLine(TextBox1.Text);
        w.Close();

     //code to convert text in a file to textbox
        StreamReader a = File.OpenText(Server.MapPath("folder/ss.txt"));
        String q = a.ReadToEnd();
        TextBox2.Text = q;
        a.Close();


    }
}

Change font color of label control dynamically in asp.net

eg:  Label1.ForeColor = System.Drawing.Color.Gray;

Read and Write data from Excel sheet - Asp.net

Write

 OleDbConnection connection = new OleDbConnection();

int i;
        string name, email;
        string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/Excel/" + filename);
        string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
        string connectionString3 = connectionString + connectionString1;
        connection.ConnectionString = connectionString3;
        string str = "select * from [Sheet1$]";
        OleDbDataAdapter adp = new OleDbDataAdapter(str, connection);
        DataTable dt = new DataTable();
        adp.Fill(dt);
        for (i = 0; i < dt.Rows.Count; i++)
        {
            obj.insert("tb_customer", "cust_name,cust_mailid", "'" + dt.Rows[i]["Customer Name"].ToString() + "','" + dt.Rows[i]["Email"].ToString() + "'");
        }
         
        GridView1.DataSource = dt;
        GridView1.DataBind();



Read

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath("Excel\\"+filename);
                       string connectionString1 = @";Extended Properties= ""Excel 8.0;HDR=YES;""";
                       string connectionString3 = connectionString +  connectionString1;
                       connection.ConnectionString = connectionString3;

                       using (DbCommand command = connection.CreateCommand())
                       {

                           string sel = "SELECT *  FROM [Sheet1$]";
                           connection.Open();
                           DataTable dt = new DataTable();
                           OleDbDataAdapter ada = new OleDbDataAdapter(sel, connectionString3);
                           ada.Fill(dt);

}