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();
back to top