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();

    }

}
back to top