Thursday, 20 December 2012

SEARCH TEXTBOX FOR GRIDVIEW USING JQUERY

 IN THE ASPX PAGE
<html>
<head runat="server">
<%-- Jquery link  --%>  
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<%-- Script  --%>   
 <script type="text/javascript">
     $(document).ready(function () {
         $('#txtcatsearch').keyup(function (event) {
             var searchKey = $(this).val().toLowerCase();
<%--3 is the column name in the gridview used to search  --%>   
             $("#catgridview tr td:nth-child(3)").each(function () {
                 var cellText = $(this).text().toLowerCase();
                 if (cellText.indexOf(searchKey) >= 0) {
                     $(this).parent().show();
                 }
                 else {
                     $(this).parent().hide();
                 }
             });
         });
     });
 </script>
</head>
<body>
<asp:TextBox ID="txtcatsearch" runat="server"></asp:TextBox>
 <asp:GridView ID="catgridview" runat="server">  
 </asp:GridView><%-- Fill the gridview using either databind in the cs page or by anyother type  --%>
</body>
</html>

Thursday, 6 December 2012

DROPDOWN LIST BINDING AND SELECTED INDEX CHANGE EVENT

CREATE A TABLE

CREATE TABLE Nametable
(
    [Nameid] [int] IDENTITY(1,1) NOT NULL,
    [Name] [varchar](50) NULL
)

IN THE ASPX PAGE

   <form id="form1" runat="server">
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged" >
    </asp:DropDownList>
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   </form>

IN THE ASPX.CS PAGE (dropdown binding and selected index change event)
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class Default7 : System.Web.UI.Page
{
    //Configuring the connection string and calling it from web.config
    static string sathya = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
    SqlConnection satcon = new SqlConnection(sathya);
    SqlDataAdapter da;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            binddrop();
        }
    }
//Binding the dropdown list with the sql database
    private void binddrop()
    {
        satcon.Open();
        da = new SqlDataAdapter("select * from Nametable",satcon);
        DataSet ds = new DataSet();
        da.Fill(ds);
        satcon.Close();
        DropDownList1.DataSource = ds;
        DropDownList1.DataTextField = "Name";
        DropDownList1.DataValueField = "Nameid";
        DropDownList1.DataBind();
    }
//SelectedIndexChanged event displaying the number according the name selected in the dropdown list
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int Nameid = Convert.ToInt32(DropDownList1.SelectedValue);        satcon.Open();
        SqlCommand cmd = new SqlCommand("select * from Mobiletable where Nameid=" + Nameid , satcon)
        SqlDataReader dr = cmd.ExecuteReader();
        dr.Read();
        TextBox1.Text = dr["Number"].ToString(); //Displaying the output filed "Number" in the texbox
        satcon.Close();
       }
}

Wednesday, 28 November 2012

POP UP DIV USING JAVASCRIPT

 <html>
<head>
<%-- JAVASCRIPT CODING  --%>  
 <script type="text/javascript" >
            function openpopup(id) {
                //Calculate Page width and height
                var pageWidth = window.innerWidth;
                var pageHeight = window.innerHeight;
                if (typeof pageWidth != "number") {
                    if (document.compatMode == "CSS1Compat") {
                        pageWidth = document.documentElement.clientWidth;
                        pageHeight = document.documentElement.clientHeight;
                    } else {
                        pageWidth = document.body.clientWidth;
                        pageHeight = document.body.clientHeight;
                    }
                }
                //Make the background div tag visible...
                var divbg = document.getElementById('bg');
                divbg.style.visibility = "visible";

                var divobj = document.getElementById(id);
                divobj.style.visibility = "visible";
                if (navigator.appName == "Microsoft Internet Explorer")
                    computedStyle = divobj.currentStyle;
                else computedStyle = document.defaultView.getComputedStyle(divobj, null);
                //Get Div width and height from StyleSheet
                var divWidth = computedStyle.width.replace('px', '');
                var divHeight = computedStyle.height.replace('px', '');
                var divLeft = (pageWidth - divWidth) / 2;
                var divTop = (pageHeight - divHeight) / 2;
                //Set Left and top coordinates for the div tag
                divobj.style.left = divLeft + "px";
                divobj.style.top = divTop + "px";
                //Put a Close button for closing the popped up Div tag
                if (divobj.innerHTML.indexOf("closepopup('" + id + "')") < 0)
                    divobj.innerHTML = "<a href=\"#\" onclick=\"closepopup('" + id + "')\"><span  class=\"close_button\">X</span></a>" + divobj.innerHTML;
            }
            function closepopup(id) {
                var divbg = document.getElementById('bg');
                divbg.style.visibility = "hidden";
                var divobj = document.getElementById(id);
                divobj.style.visibility = "hidden";
            }
</script>

 <%-- CSS CODING  --%>  
 <style type="text/css">
.popup {
      background-color: #DDD;
      height: 600px; width: 500px;
      border: 5px solid #666;
      position: absolute; visibility: hidden;
      font-family: Verdana, Geneva, sans-serif;
      font-size: small; text-align: justify;
      padding: 5px; overflow: auto;
      z-index: 999;
}
.popup_bg {
      position: absolute;
      visibility: hidden;
      height: 100%; width: 100%;
      left: 0px; top: 0px;
      filter: alpha(opacity=70); /* for IE */
      opacity: 0.7; /* CSS3 standard */
      background-color: #999;
      z-index: 1;
}
.close_button {
      font-family: Verdana, Geneva, sans-serif;
      font-size: small; font-weight: bold;
      float: right; color: #666;
      display: block; text-decoration: none;
      border: 2px solid #666;
      padding: 0px 3px 0px 3px;
}
body { margin: 0px; }
</style>
</head>
<body>
<%--CALLING THE OPENPOPUP FUNCTION  --%>
 <a href = "#" onclick="openpopup('popup1')"> CLICK HERE TO OPEN POPUP DIV </a>
 <div id="popup1" class="popup">
    HI, DUDE...
    WELCOME TO OUR POP UP DIV
 </div>
<div id="bg" class="popup_bg"></div> 
</body>
</html>

RETRIEVING THE IMAGE FROM DATABASE AND DISPLAYING IN DATALIST

CREATE TABLE

CREATE TABLE Tablename
(
[ImageID] [int] IDENTITY(1,1) NOT NULL,
[Images] [image] NULL,
[ImageName] [varchar](max) NULL,
)

IN THE ASPX

<asp:DataList ID="DataList1" runat="server" RepeatColumns="3" DataKeyField="ImageID" CellPadding="15" Width="500px">
       <ItemTemplate>
                <div>
                      <asp:Image ID ="img" Width ="120px" Height="120px"  runat="server" 
ImageUrl ='<%#   "Handler.ashx?ImageID= " + Eval ("ImageID") %> '></asp:Image>
               </div>
</br>
                <div>
                   <asp:Label ID ="lblName" ForeColor="#FFFFFF"  runat="server"
Text ='<%# Eval ("ImageName") %>'></asp:Label>
 <br />
       </ItemTemplate>
</asp:DataList>

IN THE HANDLER PAGE 

Add New Item -> Select Generic handler -> Add the below coding in the Handler.ashx

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public class Handler : IHttpHandler {
    static string constr = ConfigurationManager.ConnectionStrings["addname"].ConnectionString;
    SqlConnection con = new SqlConnection(constr); //Configuring using connection string from the  webconfig
    
    public void ProcessRequest (HttpContext context)   
    {
        string imgID = context.Request.QueryString["ImageID"].ToString();
        SqlCommand cmd = new SqlCommand("select * from Tablename where ImageID=" + imgID, con);
        con.Open();
        SqlDataReader Dr = cmd.ExecuteReader();
        Dr.Read();    
        context.Response.BinaryWrite((byte[]) Dr["Images"]);
        con.Close();
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
}

IN THE ASPX.CS

//These namespaces should be included
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

public partial class Default : System.Web.UI.Page
{
    static string constr = ConfigurationManager.ConnectionStrings["giricon"].ConnectionString;
    SqlConnection con = new SqlConnection(constr);//Calling connection string from the web.config
    SqlDataAdapter adp = new SqlDataAdapter();
    DataTable dt = new DataTable();
 protected void Page_Load(object sender, EventArgs e)
    {
     if (!Page.IsPostBack)
        {
           binding();
        }
    }
 private void binding()
    {
        adp = new SqlDataAdapter("Select * from tablename", con);
        adp.Fill(dt);
        adp.Dispose();
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }
}

GRIDVIEW MAIL USING ASP.NET C#

 IN THE ASPX PAGE

  <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">
       </asp:GridView>
    </div>
        <asp:Button ID="btnSendMail" runat="server" Text="Send Gridview Mail"
        onclick="btnSendMail_Click" Width="123px" />
    <br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    </form>

IN THE ASXP.CS PAGE
//Name space to be used
using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Net.Mail;
using System.Text;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;

public partial class Default : System.Web.UI.Page
{
    static string strcon = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
    //create new sqlconnection and connection to database by using connection string from web.config file
    SqlConnection con = new SqlConnection(strcon);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridview();
        }
    }

    // This method is used to bind gridview from database
    protected void BindGridview()
    {
      
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from tablename", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
//Send mail button click event
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        string to = TextBox1.Text;//Gets the TO id
        string From = "fromid@gmail.com";
        string subject = "Mark Detail";
        string Body = "HI ,<br>  Check d Attachment <br><br>";
        Body += GridViewToHtml(GridView1);
        Body += "<br><br>Regards,<br>sathya";
        bool send = send_mail(to, From, subject, Body);
        if (send == true)
        {
            string CloseWindow = "alert('Mail Sent Successfully!');";
            ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
        }
        else
        {
            string CloseWindow = "alert('Problem in Sending mail');";
            ClientScript.RegisterStartupScript(this.GetType(), "CloseWindow", CloseWindow, true);
        }

    }
//Mail function
    public bool send_mail(string to, string from, string subject, string body)
    {
        MailMessage msg = new MailMessage(from, to);
        msg.Subject = subject;
        AlternateView view;
        SmtpClient client;
        StringBuilder msgText = new StringBuilder();
        msgText.Append(" <html><body><br></body></html> <br><br><br>  " + body);
        view = AlternateView.CreateAlternateViewFromString(msgText.ToString(), null, "text/html");

        msg.AlternateViews.Add(view);
        client = new SmtpClient();
        client.Host = "smtp.gmail.com";
        client.Port = 587;
        client.Credentials = new System.Net.NetworkCredential("fromid@gmail.com", "fromidpassword");
        client.EnableSsl = true; //Gmail works on Server Secured Layer
        client.Send(msg);
        bool k = true;
        return k;
    }
//calling the html of the gridview
    private string GridViewToHtml(GridView gv)
    {
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        gv.RenderControl(hw);
        return sb.ToString();
    }
    public override void VerifyRenderingInServerForm(Control control)
    {
        //Confirms that an HtmlForm control is rendered for the specified ASP.NET server control at run time.
    }
}

Tuesday, 20 November 2012

JQUERY FOR GO TO TOP SCROLL

<html>
<head >

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type='text/javascript'>
         $(function () {
             $.fn.scrollToTop = function () {
                 $(this).hide().removeAttr("href");
                 if ($(window).scrollTop() != "0") {
                     $(this).fadeIn("slow")
                 }
                 var scrollDiv = $(this);
                 $(window).scroll(function () {
                     if ($(window).scrollTop() == "0") {
                         $(scrollDiv).fadeOut("slow")
                     } else {
                         $(scrollDiv).fadeIn("slow")
                     }
                 });
                 $(this).click(function () {
                     $("html, body").animate({
                         scrollTop: 0
                     }, "slow")
                 })
             }
         });
         $(function () {
             $("#hb-gotop").scrollToTop();
         });
    </script> 
<style type="text/css">
 #hb-gotop
  {
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  width:80px;
  background-color: #fff198;
  filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#99EEEEEE',EndColorStr='#99EEEEEE');
  text-align:center;
  padding:5px;
  position:fixed;
  bottom:10px;
  right:10px;
  cursor:pointer;
  color:#444;
  text-decoration:none;
  border:1px solid #C9C9C9;
  }
 </style>  


</head >
<body>
<form id="form1" runat="server">

    </form>

        <a href='#gv' id='hb-gotop' style='display:none;'>Go to Top</a>


</body>
</html>

Monday, 19 November 2012

IMAGE UPLOAD INTO SQL DATABASE

CREATE A TABLE IN SQL

Create table uploadimage
(

  [ImageID] [int] IDENTITY(1,1) NOT NULL,
[Images] [image] NULL,
[ImageName] [varchar](max) NULL,

)

IN THE ASPX PAGE

   <form id="form1" runat="server">
        <div>
        <asp:Label ID="lblfu" runat="server" Text="Image Upload"></asp:Label>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <br />
     
        <asp:Label ID="lblimgname" runat="server" Text="Image Name" ></asp:Label>
        <asp:TextBox ID="txtimgname" runat="server"></asp:TextBox>
        <br />
   
        <asp:Button ID="btnupload" runat="server" Text="Upload" onclick="btnupload_Click" />
        <asp:Label ID="lblmsg"  runat="server" Text=""></asp:Label>
        <br/>
     
    </div>
    </form>

IN THE ASPX.CS PAGE(In the Upload button click event)

    static string constr = ConfigurationManager.ConnectionStrings["stringname"].ConnectionString;
    SqlConnection con = new SqlConnection(constr); //configuring connection string from the webconfig


 protected void btnupload_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
            HttpPostedFile myimg = FileUpload1.PostedFile;
            myimg.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);
            SqlCommand cmd = new SqlCommand("insert into pimage(Images,ImageName) values          (@images,@imageName)", con);


            SqlParameter uploadimg = new SqlParameter("@images", SqlDbType.Image);
            uploadimg.Value = img;
            cmd.Parameters.Add(uploadimg);

            SqlParameter imgname = new SqlParameter("@imageName", SqlDbType.VarChar, 100);
            imgname.Value = txtimgname.Text;
            cmd.Parameters.Add(imgname);


            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            lblmsg.Text = "Image uploaded";
            txtimgname.Text = "";
     
        }
        else
        {
            lblmsg.Text = "Image upload unsuccessfull";
        }
    }


Tuesday, 16 October 2012

UPPERCASE IN TEXTBOX

The text  can be entered only in the UPPERCASE  using the following two types..

1st Type:Using CssClass or StyleSheet

<style type="text/css">
     .textupper
{
 text-transform: uppercase;
}

In htmlsource type as

 <asp:TextBox ID="TextBox1 runat="server" CssClass ="texupper"></asp:TextBox>

2nd Type: Using CodeBehind

TextBox1.Text.ToUpper();

Sunday, 16 September 2012

PASSING AND RETRIEVING VALUES USING QUERY STRING IN ASP.NET

 Pass and Retrieve the values using QUERY STRING in any event :

For example:

          In this I use a Button event for passing the values

         protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("nextpage.aspx?name=" + TextBox1.Text +      "&age=" + TextBox2.Text );

      // The question mark "?" denotes the query string

    }

        Retrieving the passed values from the first page in  second page during the load event

       protected void Page_Load(object sender, EventArgs e)
    {

        Label1.Text = "Hi Welcome " + Request.QueryString["name"];
        TextBox1.Text = Request.QueryString["pass"];

    }
   

Friday, 31 August 2012

ASP.NET SQL CONNECTIVITY USING WEB.CONFIG


Enter the following connection string in the web config as shown below 

<connectionStrings>

      <add name="SQLCON" connectionString="Data Source=OFFICE-PC\SQLEXPRESS;Initial            Catalog=databasename;Integrated Security=true;User id=sa;Password=;"/>

</connectionStrings>

Call the above in the aspx.cs page as shown below in the page load or as public

//Use this sql namespace at the starting along with the other namespaces as shown 
Using System.Data.SqlClient

//Calling the Connectionstring

static string strcon = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
//Create new sqlconnection and connection to database by using connection string from web.config file SqlConnection con = new SqlConnection(strcon);




Friday, 17 August 2012

MESSAGE BOX IN C#


if (MessageBox.Show(”Do you want to delete?”, Confirm delete”,MessageBoxButtons.YesNo) == DialogResult.Yes)

{

MessageBox.Show(”Deleted”);

}

Thursday, 16 August 2012

AGE CALCULATION USING DATE OF BIRTH IN C#

DateTime olddate = Convert.ToDateTime(textBox1.Text);

DateTime newdate = DateTime.Now;

TimeSpan ts = newdate - olddate;

int differenceindays = ts.Days;

int differenceinmonths = (differenceindays / 365);

textBox5.Text = differenceinmonths.ToString();

Tuesday, 14 August 2012

AUTO NUMBER GENERATION

OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\database.mdb");

cn.open();

DataSet ds = new DataSet();

OleDbDataAdapter da = new OleDbDataAdapter("SELECT iif(max(fieldname)=Null,1,max(field name) +1) as [Number] from Tablename", cn);

da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)
{

textBox1.Text= ds.Tables[0].Rows[0]["Number"].ToString();

}

cn.close();

Wednesday, 8 August 2012

RUNTIME ERROR : "object does not contain a definition for get_Range" in MS Excel

 Microsoft.Office.Interop.Excel.Range myrange = excelsheet.get_Range(excelsheet.Cells[1, 1], excelsheet.Cells[this.dataGridView1.RowCount + 1, this.dataGridView1.Columns.Count]);


 Solution:

Include (object) as shown in the below line....................



 Microsoft.Office.Interop.Excel.Range myrange = excelsheet.get_Range((object)excelsheet.Cells[1, 1], (object)excelsheet.Cells[this.dataGridView1.RowCount + 1, this.dataGridView1.Columns.Count]);


Wednesday, 6 June 2012

FLASH SIMPLE TIP

Press F6 to set timeline after each action or move....

Monday, 14 May 2012

KEYPRESS EVENT IN C#

private void txt1_KeyPress(object sender, KeyPressEventArgs e)
{

if (e.KeyChar == (char)Keys.Enter)

{

//do something

}
}

Thursday, 10 May 2012

CALCULATION IN TEXTBOX USING Convert.ToInt32 and int.parse

                                USING Convert.ToInt32

private void button1_Click(object sender, EventArgs e)
{
int value1 = Convert.ToInt32(this.textBox1.Text);

int value2 = Convert.ToInt32(this.textBox2.Text);

int value3 = Convert.ToInt32(this.textBox3.Text);

int value4 = (value2-value1) * value3;

 this.textBox4.Text = value4.ToString();

 }
USING  int.Parse
private void button1_Click(object sender, EventArgs e)
{

int value1 =(textBox1.Text);

int value2 = int.Parse(textBox2.Text);

int value3 = int.Parse(label1.Text);

intvalue4 = (value2-value1) * value3;

textBox4.Text = value4.ToString();
}

Sunday, 6 May 2012

COOKIES IN ASP.NET

protected void Page_Load(object sender, EventArgs e)
{

TextBox1.Text = "Ajith";
TextBox2.Text = "bmw";
HttpCookie usercars = Request.HttpCookie["favouritecar"];
if(usecookie == null)
{

HttpCookie usecar = new HttpCookie("favouritecar");
 usecar["name"] = TextBox1.Text.ToString();
 usecar["car"] = TextBox2.Text.ToString();
 usecar.Expires.DateTime.Now.AddDays(1);
Response.Cookie.Add(usecar);

}
else
{

String name =usercars["name"];
String car = usercars["car"];
Label1.Text =  "hi" + name + "is using" +car ;

}
}
}

COUNTING CLICK USING VIEWSTATE

protected void Button1_Click(object sender, EventArgs e)
    {
int click = 1;
if(ViewState["clickcount"] == nul)
{
 click = 1;
}
else
{
click = (int)ViewState["clickcount"] + 1;
}
ViewState["clickcount] = click;
Label1.Text = "Buttonclick" + click + "times";
}

Friday, 4 May 2012

BASIC MOTION USING FLASH

      Open flash --> open file and select new flash document --> Select or open a picture 
 -->Right click at the starting of the time frame --> select Insert keyframe 
--> Similarly right click at any second of the time frame as ending and select Insert
      keyframe --> Move the picture --> Now right click at the starting of the time frame and 
     Create Motion Tween--> Finally press Ctrl Enter...

      The picture will move from one place to another as we moved..

Monday, 30 April 2012

TO PERFORM BULK COPY FROM ONE DATABASE TO ANOTHER IN ASP.NET



C#
  
  using system.data.sqlclient;

button click
{

    string sqlQuery = "Select * From publishers";
    string connString = "Data Source=Local;Initial Catalog=PUBS;Integrated Security=True";
    SqlConnection sourceConn= new SqlConnection(connString);
    SqlConnection destConn = new SqlConnection(connString);
    sourceConn.Open();
    destConn.Open();
    SqlCommand command = new SqlCommand(sqlQuery, sourceConn);
    SqlDataReader reader = command.ExecuteReader();
    SqlBulkCopy bulkCopy = new SqlBulkCopy(destConn);
    bulkCopy.DestinationTableName = "BulkCopyPublishers";
    bulkCopy.WriteToServer(reader);
    bulkCopy.Close();
    sourceConn.Close();
    destConn.Close();
    Label1.Text = "Data copied successfully";
}

Saturday, 28 April 2012

MAIL GRID VIEW USING ASP.NET

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using System.IO;
using System.Text;

public partial class Csharp : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    }


    public void fn_AttachGrid()

    {

        StringWriter stw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(stw);

        GridView1.RenderControl(hw);

        MailMessage mail = new MailMessage();

        mail.IsBodyHtml = true;

        mail.To.Add(new MailAddress("toMail@domain.com"));

        mail.Subject = "Sales Report";

        System.Text.Encoding Enc = System.Text.Encoding.ASCII;

        byte[] mBArray = Enc.GetBytes(stw.ToString());

        System.IO.MemoryStream mAtt = new System.IO.MemoryStream(mBArray, false);

        mail.Attachments.Add(new Attachment(mAtt, "sales.xls"));

        mail.Body = "Hi PFA";

        SmtpClient smtp = new SmtpClient();

        mail.From = new MailAddress("fromMail@domain.com", "Your Name");

        smtp.Host = "mail.domain.com";

        smtp.UseDefaultCredentials = false;

        smtp.Credentials = new System.Net.NetworkCredential(@"Username", "Password");

        smtp.EnableSsl = true;

        smtp.Send(mail);

        lbldisplay.Text = "Email Sent";

    }

    public override void VerifyRenderingInServerForm(Control control)

    {

    }


    protected void btnSendMail_Click(object sender, EventArgs e)

    {
fn_AttachGrid();

    }

}

Friday, 27 April 2012

URL TO VIEW TRACK IT JOBS STATISTIC

                                         http://www.itjobswatch.co.uk/

SENDING EMAIL USING ASP.NET

 protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress("fromaddress@gmail.com");

            msg.To.Add(Totestbox.Text);

            msg.Subject = subtextbox.Text;

            msg.IsBodyHtml = true;

            msg.Body = bodytextbox.Text;

            msg.Priority = MailPriority.High;

            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);

            client.UseDefaultCredentials = false;

            client.Credentials = new System.Net.NetworkCredential("fromaddress@gmail.com", "password");

            client.Port = 587;

            client.Host = "smtp.gmail.com";

            client.EnableSsl = true;

            client.Send(msg);
            Label1.Text = "mail sent";
        }
        catch (Exception ex)
        {
            Label1.Text ="mail not sent" + ex.Message ;
        }

    } 

ASCII CODES

Key     Code
backspace     8
tab     9
enter     13
shift     16
ctrl     17
alt     18
pause/break     19
caps lock     20
escape     27
page up     33
page down     34
end     35
home     36
left arrow     37
up arrow     38
right arrow     39
down arrow     40
insert     45
delete     46
0     48
1     49
2     50
3     51
4     52
5     53
6     54
7     55
8     56
9     57
a     65
b     66
c     67
d     68
        
Key     Code
e     69
f     70
g     71
h     72
i     73
j     74
k     75
l     76
m     77
n     78
o     79
p     80
q     81
r     82
s     83
t     84
u     85
v     86
w     87
x     88
y     89
z     90
left window key     91
right window key     92
select key     93
numpad 0     96
numpad 1     97
numpad 2     98
numpad 3     99
numpad 4     100
numpad 5     101
numpad 6     102
numpad 7     103
        
Key     Code
numpad 8     104
numpad 9     105
multiply     106
add     107
subtract     109
decimal point     110
divide     111
f1     112
f2     113
f3     114
f4     115
f5     116
f6     117
f7     118
f8     119
f9     120
f10     121
f11     122
f12     123
num lock     144
scroll lock     145
semi-colon     186
equal sign     187
comma     188
dash     189
period     190
forward slash     191
grave accent     192
open bracket     219
back slash     220
close braket     221
single quote     222
    

DISABLE BACK BUTTON

<script type = "text/javascript">

function disableBackButton(){ 

window.history.forward();

}
</script>

</head> 

<body onload="disableBackButton()">

</body>
back to top